n = int(input())

tree = [[] for _ in range(n+1)]

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

color = [-1] * (n+1)
color[1] = 0
stack = [1]

while stack:
    node = stack.pop()
    for vertex, weight in tree[node]:
        if color[vertex] != -1:
            continue
        color[vertex] = (color[node] + weight) % 2
        stack.append(vertex)

print("\n".join(map(str, color[1:])))


 n = int(input()) n int(input()) int input() input [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] tree = [[] for _ in range(n+1)] tree [[] for _ in range(n+1)] for _ in range(n-1):
    u, v, w = map(int, input().split())
    tree[u].append([v, w])
    tree[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 tree[u].append([v, w]) [u].append [u] tree u append [v, w] v w tree[v].append([u, w]) [v].append [v] tree v append [u, w] u w color = [-1] * (n+1) color [-1] * (n+1) [-1] -1 n+1 n 1 color[1] = 0 color[1] color 1 0 stack = [1] stack [1] 1 while stack:
    node = stack.pop()
    for vertex, weight in tree[node]:
        if color[vertex] != -1:
            continue
        color[vertex] = (color[node] + weight) % 2
        stack.append(vertex) stack node = stack.pop() node stack.pop() stack.pop stack pop for vertex, weight in tree[node]:
        if color[vertex] != -1:
            continue
        color[vertex] = (color[node] + weight) % 2
        stack.append(vertex) vertex weight tree[node] tree node if color[vertex] != -1:
            continue
         color[vertex] != -1 color[vertex] color vertex -1 continue color[vertex] = (color[node] + weight) % 2 color[vertex] color vertex (color[node] + weight) % 2 color[node] + weight color[node] color node weight 2 stack.append(vertex) stack.append stack append vertex print("\n".join(map(str, color[1:]))) print "\n".join(map(str, color[1:])) "\n".join "\n" join map(str, color[1:]) map str color[1:] color 1: 1 node = stack.pop() stack.pop() node v, w = map(int, input().split()) map(int, input().split()) v n = int(input()) int(input()) n w = map(int, input().split()) map(int, input().split()) w tree = [[] for _ in range(n+1)] [[] for _ in range(n+1)] tree u, v, w = map(int, input().split()) map(int, input().split()) u color = [-1] * (n+1) [-1] * (n+1) color stack = [1] [1] stack
n = int(input())

tree = [[] for _ in range(n+1)]

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

color = [-1] * (n+1)
color[1] = 0
stack = [1]

while stack:
    node = stack.pop()
    for vertex, weight in tree[node]:
        if color[vertex] != -1:
            continue
        color[vertex] = (color[node] + weight) % 2
        stack.append(vertex)

print("\n".join(map(str, color[1:])))



