N = int(input())
ans = [-1] * N
ans[0] = 0
root = [[] for i in range(N)]
for i in range(N - 1):
  u, v, w = map(int, input().split())
  root[u - 1].append([v - 1, w])
  root[v - 1].append([u - 1, w])
#print(root)

visited = [0] * N
visited[0] = 1
queue = [0]
while queue:
  x = queue.pop()
  for i, value in root[x]:
    if value % 2 == 0:
      ans[i] = ans[x]
    else:
      ans[i] = abs(1 - ans[x])
    if visited[i] == 0:
      visited[i] = 1
      queue.append(i)
      
#print(ans)      
for i in range(N):
  print(ans[i])
              
      
      
      
      
      
 N = int(input()) N int(input()) int input() input ans = [-1] * N ans [-1] * N [-1] -1 N ans[0] = 0 ans[0] ans 0 0 [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] root = [[] for i in range(N)] root [[] for i in range(N)] for i in range(N - 1):
  u, v, w = map(int, input().split())
  root[u - 1].append([v - 1, w])
  root[v - 1].append([u - 1, w])
#print(root) i 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 root[u - 1].append([v - 1, w]) [u - 1].append [u - 1] root u - 1 u 1 append [v - 1, w] v - 1 v 1 w root[v - 1].append([u - 1, w]) [v - 1].append [v - 1] root v - 1 v 1 append [u - 1, w] u - 1 u 1 w visited = [0] * N visited [0] * N [0] 0 N visited[0] = 1 visited[0] visited 0 1 queue = [0] queue [0] 0 while queue:
  x = queue.pop()
  for i, value in root[x]:
    if value % 2 == 0:
      ans[i] = ans[x]
    else:
      ans[i] = abs(1 - ans[x])
    if visited[i] == 0:
      visited[i] = 1
      queue.append(i)
      
#print(ans)       queue x = queue.pop() x queue.pop() queue.pop queue pop for i, value in root[x]:
    if value % 2 == 0:
      ans[i] = ans[x]
    else:
      ans[i] = abs(1 - ans[x])
    if visited[i] == 0:
      visited[i] = 1
      queue.append(i)
      
#print(ans)       i value root[x] root x if value % 2 == 0:
      ans[i] = ans[x]
    else:
      ans[i] = abs(1 - ans[x])
     value % 2 == 0 value % 2 value 2 0 ans[i] = ans[x] ans[i] ans i ans[x] ans x ans[i] = abs(1 - ans[x]) ans[i] ans i abs(1 - ans[x]) abs 1 - ans[x] 1 ans[x] ans x if visited[i] == 0:
      visited[i] = 1
      queue.append(i)
      
#print(ans)       visited[i] == 0 visited[i] visited i 0 visited[i] = 1 visited[i] visited i 1 queue.append(i) queue.append queue append i for i in range(N):
  print(ans[i])
              
      
      
      
      
       i range(N) range N print(ans[i]) print ans[i] ans i root = [[] for i in range(N)] [[] for i in range(N)] root u, v, w = map(int, input().split()) map(int, input().split()) u v, w = map(int, input().split()) map(int, input().split()) v queue = [0] [0] queue visited = [0] * N [0] * N visited N = int(input()) int(input()) N w = map(int, input().split()) map(int, input().split()) w ans = [-1] * N [-1] * N ans x = queue.pop() queue.pop() x
N = int(input())
ans = [-1] * N
ans[0] = 0
root = [[] for i in range(N)]
for i in range(N - 1):
  u, v, w = map(int, input().split())
  root[u - 1].append([v - 1, w])
  root[v - 1].append([u - 1, w])
#print(root)

visited = [0] * N
visited[0] = 1
queue = [0]
while queue:
  x = queue.pop()
  for i, value in root[x]:
    if value % 2 == 0:
      ans[i] = ans[x]
    else:
      ans[i] = abs(1 - ans[x])
    if visited[i] == 0:
      visited[i] = 1
      queue.append(i)
      
#print(ans)      
for i in range(N):
  print(ans[i])
              
      
      
      
      
      

