Language: Java

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer>[] g = new ArrayList[n + 1];
		for (int i = 0; i < g.length; i++) {
			g[i] = new ArrayList<>();
		}

		long[][] ws = new long[n + 1][n + 1];
		for (int i = 0; i < ws.length; i++) {
			Arrays.fill(ws[i], Integer.MAX_VALUE);
			ws[i][i] = 0;
		}

		for (int i = 0; i < n - 1; i++) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			long w = sc.nextLong();
			g[u].add(v);
			g[v].add(u);
			ws[u][v] = w;
			ws[v][u] = w;
		}


		//for (int i = 0; i < n; i++) {
		//	for (int j = 0; j < n; j++) {
		//		System.out.print(ws[i][j]);
		//		System.out.print(" ");
		//	}
		//	System.out.println();
		//}

		int[] a = new int[n];
		Queue<Integer> q = new LinkedList<>();
		Queue<Integer> r = new LinkedList<>();
		q.offer(0);

		boolean[] visited = new boolean[n];
		while (!q.isEmpty() || !r.isEmpty()) {
			int current = 0;
			while (!q.isEmpty()) {
				long p = q.poll();
				//System.out.print("q ");
				//System.out.println(p);
				if (visited[p]) continue;
				visited[p] = true;

				a[p] = current;
				for (int i = 0; i < g[p].size(); i++) {
					int x = g[p].get(i);
					if (visited[x]) continue;
					if (ws[p][x] % 2 == 0) q.offer(x);
					else r.offer(x);
				}
			}

			current = 1;
			while (!r.isEmpty()) {
				long p = r.poll();
				//System.out.print("r ");
				//System.out.println(p);
				if (visited[p]) continue;
				visited[p] = true;

				a[p] = current;
				for (int i = 0; i < g[p].size(); i++) {
					int x = g[p].get(i);
					if (visited[x]) continue;
					if (ws[p][x] % 2 == 0) r.offer(x);
					else q.offer(x);
				}
			}
		}

		for (int i = 0; i < a.length; i++) {
			System.out.println(a[i]);
		}
	}
}


Compiler output:
Main.java:49: error: incompatible types: possible lossy conversion from long to int
				if (visited[p]) continue;
				            ^
Main.java:50: error: incompatible types: possible lossy conversion from long to int
				visited[p] = true;
				        ^
Main.java:52: error: incompatible types: possible lossy conversion from long to int
				a[p] = current;
				  ^
Main.java:53: error: incompatible types: possible lossy conversion from long to int
				for (int i = 0; i < g[p].size(); i++) {
				                      ^
Main.java:54: error: incompatible types: possible lossy conversion from long to int
					int x = g[p].get(i);
					          ^
Main.java:56: error: incompatible types: possible lossy conversion from long to int
					if (ws[p][x] % 2 == 0) q.offer(x);
					       ^
Main.java:66: error: incompatible types: possible lossy conversion from long to int
				if (visited[p]) continue;
				            ^
Main.java:67: error: incompatible types: possible lossy conversion from long to int
				visited[p] = true;
				        ^
Main.java:69: error: incompatible types: possible lossy conversion from long to int
				a[p] = current;
				  ^
Main.java:70: error: incompatible types: possible lossy conversion from long to int
				for (int i = 0; i < g[p].size(); i++) {
				                      ^
Main.java:71: error: incompatible types: possible lossy conversion from long to int
					int x = g[p].get(i);
					          ^
Main.java:73: error: incompatible types: possible lossy conversion from long to int
					if (ws[p][x] % 2 == 0) r.offer(x);
					       ^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
12 errors