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

color = [-1]*N
color[0] = 0

import queue
q = queue.Queue()
q.put(0)
while not q.empty():
    v = q.get()
    for c, w in G[v]:
        if color[c] >= 0: continue
        color[c] = (color[v] + w)%2
        q.put(c)

print('\n'.join(map(str, color))) 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) [] G = [[] for _ in range(N)] G [[] for _ in range(N)] for _ in range(N-1):
    u, v, w = map(int, input().split())
    G[u-1].append((v-1, w))
    G[v-1].append((u-1, 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 G[u-1].append((v-1, w)) [u-1].append [u-1] G u-1 u 1 append (v-1, w) v-1 v 1 w G[v-1].append((u-1, w)) [v-1].append [v-1] G v-1 v 1 append (u-1, w) u-1 u 1 w color = [-1]*N color [-1]*N [-1] -1 N color[0] = 0 color[0] color 0 0 import queue queue q = queue.Queue() q queue.Queue() queue.Queue queue Queue q.put(0) q.put q put 0 while not q.empty():
    v = q.get()
    for c, w in G[v]:
        if color[c] >= 0: continue
        color[c] = (color[v] + w)%2
        q.put(c) not q.empty() q.empty() q.empty q empty v = q.get() v q.get() q.get q get for c, w in G[v]:
        if color[c] >= 0: continue
        color[c] = (color[v] + w)%2
        q.put(c) c w G[v] G v if color[c] >= 0: continue
         color[c] >= 0 color[c] color c 0 color[c] = (color[v] + w)%2 color[c] color c (color[v] + w)%2 color[v] + w color[v] color v w 2 q.put(c) q.put q put c print('\n'.join(map(str, color))) print '\n'.join(map(str, color)) '\n'.join '\n' join map(str, color) map str color N = int(input()) int(input()) N v = q.get() q.get() v w = map(int, input().split()) map(int, input().split()) w color = [-1]*N [-1]*N color v, w = map(int, input().split()) map(int, input().split()) v q = queue.Queue() queue.Queue() q G = [[] for _ in range(N)] [[] for _ in range(N)] G u, v, w = map(int, input().split()) map(int, input().split()) u
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    G[u-1].append((v-1, w))
    G[v-1].append((u-1, w))

color = [-1]*N
color[0] = 0

import queue
q = queue.Queue()
q.put(0)
while not q.empty():
    v = q.get()
    for c, w in G[v]:
        if color[c] >= 0: continue
        color[c] = (color[v] + w)%2
        q.put(c)

print('\n'.join(map(str, color)))