# -*- coding: utf-8 -*-

from collections import defaultdict

n = int(eval(input()))

e = defaultdict(lambda: [])



for _ in range(n-1):

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

    v -= 1

    u -= 1

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

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



col = [-1]*n

q = [0]

col[0] = 0

while len(q)>0:

    v = q.pop()

    for u,w in e[v]:

        if col[u]<0:

            if w%2==1:

                col[u] = (col[v]+1)%2

            else:

                col[u] = col[v]

            q.append(u)



print((*col))
n = int(eval(input()))

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

for _ in range(n-1):

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

    u -= 1

    v -= 1

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

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



res = [-1]*n

res[0] = 0

q = [0]

while len(q):

    v = q.pop()

    for u,w in e[v]:

        if res[u]>=0:

            continue

        res[u] = res[v]+w

        q.append(u)



for r in res:

    print((r%2))

# -*- coding: utf-8 -*-
from collections import defaultdict

n = int(eval(input()))
e = defaultdict(lambda: [])
for _ in range(n - 1):
    v, u, w = list(map(int, input().split()))
    v -= 1
    u -= 1
    e[v].append((u, w))
    e[u].append((v, w))
col = [-1] * n
q = [0]
col[0] = 0
while len(q) > 0:
    v = q.pop()
    for u, w in e[v]:
        if col[u] < 0:
            if w % 2 == 1:
                col[u] = (col[v] + 1) % 2
            else:
                col[u] = col[v]
            q.append(u)
print((*col))

n = int(eval(input()))
e = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    e[u].append((v, w))
    e[v].append((u, w))
res = [-1] * n
res[0] = 0
q = [0]
while len(q):
    v = q.pop()
    for u, w in e[v]:
        if res[u] >= 0:
            continue
        res[u] = res[v] + w
        q.append(u)
for r in res:
    print((r % 2))

-# -*- coding: utf-8 -*- -from collections import defaultdict - -e = defaultdict(lambda: []) +e = [[] for _ in range(n)] -    v, u, w = list(map(int, input().split())) +    u, v, w = list(map(int, input().split())) +    u -= 1 -    u -= 1 +    e[u].append((v, w)) -    e[u].append((v, w)) -col = [-1] * n +res = [-1] * n +res[0] = 0 -col[0] = 0 -while len(q) > 0: +while len(q): -        if col[u] < 0: -            if w % 2 == 1: -                col[u] = (col[v] + 1) % 2 -            else: -                col[u] = col[v] -            q.append(u) -print((*col)) +        if res[u] >= 0: +            continue +        res[u] = res[v] + w +        q.append(u) +for r in res: +    print((r % 2))