Language: Java

import java.util.*;

public class Main {
  public int P = 1;
  public int[] c;
  public int[] d;
  HashMap<Integer, ArrayList<Integer>> map1;
  HashMap<int[][], Integer> map2;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] u = new int[n - 1];
    int[] v = new int[n - 1];
    int[] w = new int[n - 1];
    map1 = new HashMap<Integer, ArrayList<Integer>>();
    map2 = new HashMap<int[][], Integer>();
    c = new int[n];
    d = new int[n];
    for(int i = 0; i < n - 1; i++) {
      u[i] = sc.nextInt() - 1;
      v[i] = sc.nextInt() - 1;
      w[i] = sc.nextInt();
      if(map1.containsKey(u[i])) {
        ArrayList<Integer> list = map1.get(u[i]);
        list.add(v[i]);
        map1.put(u[i], list);
      } else {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(v[i]);
        map1.put(u[i], list);
      }
      
      if(map1.containsKey(v[i])) {
        ArrayList<Integer> list = map1.get(v[i]);
        list.add(u[i]);
        map1.put(v[i], list);
      } else {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(u[i]);
        map1.put(v[i], list);
      }

      int[][] s1 = {u[i], v[i]};
      int[][] s2 = {v[i], u[i]};
      map2.put(s1, w[i]);
      map2.put(s2, w[i]);
    }

    c[0] = 0;
    d[0] = 1;
    
    dfs(0);
    for(int i = 0; i < n; i++) {
      System.out.println(c[i]);
    }
  }

  public void dfs(int g) {
    ArrayList<Integer> list1 = map1.get(g);
    for(int i = 0; i < list1.size(); i++) {
      int f = list1.get(i);
      if(d[f] == 0) {
        d[f] = 1;
        int[][] a = {g, f};
        int b = map2.get(a);
        if(b % 2 == 0) {
          c[f] = c[g];
        } else {
          c[f] = 1 - c[g];
        }
        dfs(f);
      }
    }
  }
}

Compiler output:
Main.java:15: error: non-static variable map1 cannot be referenced from a static context
    map1 = new HashMap<Integer, ArrayList<Integer>>();
    ^
Main.java:16: error: non-static variable map2 cannot be referenced from a static context
    map2 = new HashMap<int[][], Integer>();
    ^
Main.java:17: error: non-static variable c cannot be referenced from a static context
    c = new int[n];
    ^
Main.java:18: error: non-static variable d cannot be referenced from a static context
    d = new int[n];
    ^
Main.java:23: error: non-static variable map1 cannot be referenced from a static context
      if(map1.containsKey(u[i])) {
         ^
Main.java:24: error: non-static variable map1 cannot be referenced from a static context
        ArrayList<Integer> list = map1.get(u[i]);
                                  ^
Main.java:26: error: non-static variable map1 cannot be referenced from a static context
        map1.put(u[i], list);
        ^
Main.java:30: error: non-static variable map1 cannot be referenced from a static context
        map1.put(u[i], list);
        ^
Main.java:33: error: non-static variable map1 cannot be referenced from a static context
      if(map1.containsKey(v[i])) {
         ^
Main.java:34: error: non-static variable map1 cannot be referenced from a static context
        ArrayList<Integer> list = map1.get(v[i]);
                                  ^
Main.java:36: error: non-static variable map1 cannot be referenced from a static context
        map1.put(v[i], list);
        ^
Main.java:40: error: non-static variable map1 cannot be referenced from a static context
        map1.put(v[i], list);
        ^
Main.java:43: error: incompatible types: int cannot be converted to int[]
      int[][] s1 = {u[i], v[i]};
                     ^
Main.java:43: error: incompatible types: int cannot be converted to int[]
      int[][] s1 = {u[i], v[i]};
                           ^
Main.java:44: error: incompatible types: int cannot be converted to int[]
      int[][] s2 = {v[i], u[i]};
                     ^
Main.java:44: error: incompatible types: int cannot be converted to int[]
      int[][] s2 = {v[i], u[i]};
                           ^
Main.java:45: error: non-static variable map2 cannot be referenced from a static context
      map2.put(s1, w[i]);
      ^
Main.java:46: error: non-static variable map2 cannot be referenced from a static context
      map2.put(s2, w[i]);
      ^
Main.java:49: error: non-static variable c cannot be referenced from a static context
    c[0] = 0;
    ^
Main.java:50: error: non-static variable d cannot be referenced from a static context
    d[0] = 1;
    ^
Main.java:52: error: non-static method dfs(int) cannot be referenced from a static context
    dfs(0);
    ^
Main.java:54: error: non-static variable c cannot be referenced from a static context
      System.out.println(c[i]);
                         ^
Main.java:64: error: incompatible types: int cannot be converted to int[]
        int[][] a = {g, f};
                     ^
Main.java:64: error: incompatible types: int cannot be converted to int[]
        int[][] a = {g, f};
                        ^
24 errors