n=int(eval(input()))

L=[[] for i in range(n)]

for i in range(n-1):

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

    u-=1

    v-=1

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

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

ans=[-1]*n

ans[0]=0

que=[0]

import queue

que=queue.Queue()

que.put(0)

while not que.empty():

    v=que.get()

    for u, w in L[v]:

        if ans[u]!=-1:

            continue

        ans[u]=(ans[v]+w)%2

        que.put(u)

for a in ans:

    print(a)
n=int(eval(input()))

L=[[] for i in range(n)]

for i in range(n-1):

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

    u-=1

    v-=1

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

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

ans=[-1]*n

ans[0]=0

from collections import deque

stack=deque([])

stack.append(0)

while stack:

    v=stack.popleft()

    for u, w in L[v]:

        if ans[u]!=-1:

            continue

        ans[u]=(ans[v]+w)%2

        stack.appendleft(u)

for a in ans:

    print(a)

n = int(eval(input()))
L = [[] for i in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    L[u].append([v, w])
    L[v].append([u, w])
ans = [-1] * n
ans[0] = 0
que = [0]
import queue

que = queue.Queue()
que.put(0)
while not que.empty():
    v = que.get()
    for u, w in L[v]:
        if ans[u] != -1:
            continue
        ans[u] = (ans[v] + w) % 2
        que.put(u)
for a in ans:
    print(a)

n = int(eval(input()))
L = [[] for i in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    L[u].append([v, w])
    L[v].append([u, w])
ans = [-1] * n
ans[0] = 0
from collections import deque

stack = deque([])
stack.append(0)
while stack:
    v = stack.popleft()
    for u, w in L[v]:
        if ans[u] != -1:
            continue
        ans[u] = (ans[v] + w) % 2
        stack.appendleft(u)
for a in ans:
    print(a)

-que = [0] -import queue +from collections import deque -que = queue.Queue() -que.put(0) -while not que.empty(): -    v = que.get() +stack = deque([]) +stack.append(0) +while stack: +    v = stack.popleft() -        que.put(u) +        stack.appendleft(u)