You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
static int[] a,b;//0-index static int[] c;//1-index static int[] d;//1-index static int n; public static void main(String[] args) throws IOException{ new Solution().run(); } public static void dfscol(int root){ d[root]=1; for(int i=0;i<n-1;i++){ if(a[i]==root && d[b[i]]==0){ dfscol(b[i]); c[root]++; } if(b[i]==root && d[a[i]]==0){ b[i]=a[i]; a[i]=root; dfscol(b[i]); c[root]++; } } return; } public static int dfs(int root){ if(root > 0 && root <=n){ if(c[root]==0) {//leaf return 0; } else {//c[root]>0 int count =0; for(int i=0;i<n-1;i++){ if(a[i]==root){ count^=(int)(1+dfs(b[i])); } } return count; } } return 0; } public void run() throws IOException{ Scanner in = new Scanner(System.in); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); int i,u,v, counter; a = new int[501]; b = new int[501]; c = new int[501]; d = new int[501]; for(int tt =0;tt<t;tt++){ Arrays.fill(c,0); Arrays.fill(d,0); n = in.nextInt();//n<=500 counter = 0; for(i=0;i<n-1;i++){ u = in.nextInt();//n<=500 v = in.nextInt();//n<=500 a[i]=u; b[i]=v; } d[1]=1; dfscol(1); //dfs counter = dfs(1); //System.out.println("Node "+1+": "+counter); if(counter>0) log.write("Alice\n"); else log.write("Bob\n"); } log.flush();
} }
Seems like cookies are disabled on this browser, please enable them to open this website
Deforestation
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
} }