function Dfs(G, v, cur) {
  color[v] = cur % 2;
  for (next_v of G[v]) {
    if (color[next_v[0]] != -1) continue;
    Dfs(G, next_v[0], cur+next_v[1]);
  }
}

function Main(s) {
  var s = s.split("\n");
  n = s[0]*1;
  if (n === 1) {
    console.log(0);
    return;
  }
  var e = [[0,0]].concat(s.slice(1, n).map(e => e.split(" ").map(e => e*1)));
  var g = new Array(n+1);
  for (var i = 0; i < n+1; i++) g[i] = new Array();
  for (var i = 1; i < n; i++) {
    g[e[i][0]].push([e[i][1], e[i][2]]);
    g[e[i][1]].push([e[i][0], e[i][2]]);
  }

  color = new Array(n+1).fill(-1);

  for (var v = 1; v < n+1; v++) {
    if (color[v] != -1) continue;
    Dfs(g, v, 0);
  }

  for (var i = 1; i < n+1; i++) console.log(color[i]);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));