n=int(eval(input()))

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

q=[(1,0)]

ans=[-1]*n

while n>1:

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

    l[u]+=[(v,w)]

    l[v]+=[(u,w)]

    n-=1

while q:

    u,w=q.pop()

    ans[u-1]=w%2

    for v,d in l[u]:

        q+=[(v,w+d)]*(ans[v-1]<0)

print((*ans))

n=int(input())

l=[[] for _ in range(n)]

for _ in range(n-1):

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

    u-=1

    v-=1

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

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





iro=[-1]*n

iro[0]=1

from collections import deque

q=deque()

q.append(0)

while q:

    v=q.popleft()

    for i,w in l[v]:

        if iro[i]!=-1:

            continue

        if w%2==0:

            iro[i]=iro[v]

        else:

            iro[i]=iro[v]^1

        q.append(i)

print(*iro,sep="\n")

n = int(eval(input()))
l = [[] for _ in range(n + 1)]
q = [(1, 0)]
ans = [-1] * n
while n > 1:
    u, v, w = list(map(int, input().split()))
    l[u] += [(v, w)]
    l[v] += [(u, w)]
    n -= 1
while q:
    u, w = q.pop()
    ans[u - 1] = w % 2
    for v, d in l[u]:
        q += [(v, w + d)] * (ans[v - 1] < 0)
print((*ans))

n = int(input())
l = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    l[u].append((v, w))
    l[v].append((u, w))
iro = [-1] * n
iro[0] = 1
from collections import deque

q = deque()
q.append(0)
while q:
    v = q.popleft()
    for i, w in l[v]:
        if iro[i] != -1:
            continue
        if w % 2 == 0:
            iro[i] = iro[v]
        else:
            iro[i] = iro[v] ^ 1
        q.append(i)
print(*iro, sep="\n")

-n = int(eval(input())) -l = [[] for _ in range(n + 1)] -q = [(1, 0)] -ans = [-1] * n -while n > 1: -    u, v, w = list(map(int, input().split())) -    l[u] += [(v, w)] -    l[v] += [(u, w)] -    n -= 1 +n = int(input()) +l = [[] for _ in range(n)] +for _ in range(n - 1): +    u, v, w = map(int, input().split()) +    u -= 1 +    v -= 1 +    l[u].append((v, w)) +    l[v].append((u, w)) +iro = [-1] * n +iro[0] = 1 +from collections import deque + +q = deque() +q.append(0) -    u, w = q.pop() -    ans[u - 1] = w % 2 -    for v, d in l[u]: -        q += [(v, w + d)] * (ans[v - 1] < 0) -print((*ans)) +    v = q.popleft() +    for i, w in l[v]: +        if iro[i] != -1: +            continue +        if w % 2 == 0: +            iro[i] = iro[v] +        else: +            iro[i] = iro[v] ^ 1 +        q.append(i) +print(*iro, sep="\n")