import sys
sys.setrecursionlimit(100000)

N = int(input())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  u,v,w = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append((v,w))
  adj[v].append((u,w))

color = [None] * N
def dfs(n,l):
  if l%2==0:
    color[n] = 1
  else:
    color[n] = 0

  for nei, nl in adj[n]:
    if color[nei] is not None:
      if (l+nl) % 2 == 0 and color[nei] != 1:
        return False
      if (l+nl) % 2 == 1 and color[nei] != 0:
        return False
    else:
      dfs(nei, l+nl)

  return True

for i in range(N):
  if color[i] is None:
    if not dfs(i,0):
      print(-1)
      exit()

for c in color: print(c) import sys sys sys.setrecursionlimit(100000) sys.setrecursionlimit sys setrecursionlimit 100000 N = int(input()) N int(input()) int input() input [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] adj = [ [] for _ in range(N) ] adj [ [] for _ in range(N) ] for _ in range(N-1):
  u,v,w = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append((v,w))
  adj[v].append((u,w)) _ range(N-1) range N-1 N 1 u,v,w = map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split v w u -= 1 u 1 v -= 1 v 1 adj[u].append((v,w)) [u].append [u] adj u append (v,w) v w adj[v].append((u,w)) [v].append [v] adj v append (u,w) u w color = [None] * N color [None] * N [None] None N def dfs(n,l):
  if l%2==0:
    color[n] = 1
  else:
    color[n] = 0

  for nei, nl in adj[n]:
    if color[nei] is not None:
      if (l+nl) % 2 == 0 and color[nei] != 1:
        return False
      if (l+nl) % 2 == 1 and color[nei] != 0:
        return False
    else:
      dfs(nei, l+nl)

  return True dfs if l%2==0:
    color[n] = 1
  else:
    color[n] = 0

   l%2==0 l%2 l 2 0 color[n] = 1 color[n] color n 1 color[n] = 0 color[n] color n 0 for nei, nl in adj[n]:
    if color[nei] is not None:
      if (l+nl) % 2 == 0 and color[nei] != 1:
        return False
      if (l+nl) % 2 == 1 and color[nei] != 0:
        return False
    else:
      dfs(nei, l+nl)

   nei nl adj[n] adj n if color[nei] is not None:
      if (l+nl) % 2 == 0 and color[nei] != 1:
        return False
      if (l+nl) % 2 == 1 and color[nei] != 0:
        return False
    else:
      dfs(nei, l+nl)

   color[nei] is not None color[nei] color nei None if (l+nl) % 2 == 0 and color[nei] != 1:
        return False
       (l+nl) % 2 == 0 and color[nei] != 1 (l+nl) % 2 == 0 (l+nl) % 2 l+nl l nl 2 0 color[nei] != 1 color[nei] color nei 1 return False False if (l+nl) % 2 == 1 and color[nei] != 0:
        return False
     (l+nl) % 2 == 1 and color[nei] != 0 (l+nl) % 2 == 1 (l+nl) % 2 l+nl l nl 2 1 color[nei] != 0 color[nei] color nei 0 return False False dfs(nei, l+nl) dfs nei l+nl l nl return True True n n l l for i in range(N):
  if color[i] is None:
    if not dfs(i,0):
      print(-1)
      exit() i range(N) range N if color[i] is None:
    if not dfs(i,0):
      print(-1)
      exit() color[i] is None color[i] color i None if not dfs(i,0):
      print(-1)
      exit() not dfs(i,0) dfs(i,0) dfs i 0 print(-1) print -1 exit() exit for c in color: print(c) c color v -= 1 1 v N = int(input()) int(input()) N u,v,w = map(int,input().split()) map(int,input().split()) u u -= 1 1 u v,w = map(int,input().split()) map(int,input().split()) v color = [None] * N [None] * N color w = map(int,input().split()) map(int,input().split()) w def dfs(n,l):
  if l%2==0:
    color[n] = 1
  else:
    color[n] = 0

  for nei, nl in adj[n]:
    if color[nei] is not None:
      if (l+nl) % 2 == 0 and color[nei] != 1:
        return False
      if (l+nl) % 2 == 1 and color[nei] != 0:
        return False
    else:
      dfs(nei, l+nl)

  return True def dfs(n,l):
  if l%2==0:
    color[n] = 1
  else:
    color[n] = 0

  for nei, nl in adj[n]:
    if color[nei] is not None:
      if (l+nl) % 2 == 0 and color[nei] != 1:
        return False
      if (l+nl) % 2 == 1 and color[nei] != 0:
        return False
    else:
      dfs(nei, l+nl)

  return True dfs adj = [ [] for _ in range(N) ] [ [] for _ in range(N) ] adj
import sys
sys.setrecursionlimit(100000)

N = int(input())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  u,v,w = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append((v,w))
  adj[v].append((u,w))

color = [None] * N
def dfs(n,l):
  if l%2==0:
    color[n] = 1
  else:
    color[n] = 0

  for nei, nl in adj[n]:
    if color[nei] is not None:
      if (l+nl) % 2 == 0 and color[nei] != 1:
        return False
      if (l+nl) % 2 == 1 and color[nei] != 0:
        return False
    else:
      dfs(nei, l+nl)

  return True

for i in range(N):
  if color[i] is None:
    if not dfs(i,0):
      print(-1)
      exit()

for c in color: print(c)
