import heapq as hp

N = int(eval(input()))

ans = [-1]*N

arr = []

for i in range(N-1):

    u,v,w = list(map(int,input().split()))

    u -= 1

    v -= 1

    arr.append([u,v,w])

e_list = [[] for i in range(N)]

for u,v,w in arr:

    e_list[u].append([v,w])

    e_list[v].append([u,w])



stack = [0]

ans[0] = 0

while(stack):

    cur_pos = stack.pop()

    for des,cost in e_list[cur_pos]:

        if ans[des] >=  0:

            continue

        ans[des] = (ans[cur_pos] + cost)%2

        stack.append(des)

for i in ans:

    print(i)
N = int(input())

e_list = [[] for i in range(N)]

for i in range(N-1):

    u,v,w = map(int,input().split())

    w %= 2

    e_list[u-1].append([v-1,w])

    e_list[v-1].append([u-1,w])



stack = [0]

ans = [-1]*N

ans[0] = 0

while stack:

    x = stack.pop()

    for v,w in e_list[x]:

        if ans[v] != -1:

            continue

        else:

            ans[v] = ans[x]^w

            stack.append(v)

print(*ans,sep='\n')

import heapq as hp

N = int(eval(input()))
ans = [-1] * N
arr = []
for i in range(N - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    arr.append([u, v, w])
e_list = [[] for i in range(N)]
for u, v, w in arr:
    e_list[u].append([v, w])
    e_list[v].append([u, w])
stack = [0]
ans[0] = 0
while stack:
    cur_pos = stack.pop()
    for des, cost in e_list[cur_pos]:
        if ans[des] >= 0:
            continue
        ans[des] = (ans[cur_pos] + cost) % 2
        stack.append(des)
for i in ans:
    print(i)

N = int(input())
e_list = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    w %= 2
    e_list[u - 1].append([v - 1, w])
    e_list[v - 1].append([u - 1, w])
stack = [0]
ans = [-1] * N
ans[0] = 0
while stack:
    x = stack.pop()
    for v, w in e_list[x]:
        if ans[v] != -1:
            continue
        else:
            ans[v] = ans[x] ^ w
            stack.append(v)
print(*ans, sep="\n")

-import heapq as hp - -N = int(eval(input())) +N = int(input()) +e_list = [[] for i in range(N)] +for i in range(N - 1): +    u, v, w = map(int, input().split()) +    w %= 2 +    e_list[u - 1].append([v - 1, w]) +    e_list[v - 1].append([u - 1, w]) +stack = [0] -arr = [] -for i in range(N - 1): -    u, v, w = list(map(int, input().split())) -    u -= 1 -    v -= 1 -    arr.append([u, v, w]) -e_list = [[] for i in range(N)] -for u, v, w in arr: -    e_list[u].append([v, w]) -    e_list[v].append([u, w]) -stack = [0] -    cur_pos = stack.pop() -    for des, cost in e_list[cur_pos]: -        if ans[des] >= 0: +    x = stack.pop() +    for v, w in e_list[x]: +        if ans[v] != -1: -        ans[des] = (ans[cur_pos] + cost) % 2 -        stack.append(des) -for i in ans: -    print(i) +        else: +            ans[v] = ans[x] ^ w +            stack.append(v) +print(*ans, sep="\n")