from collections import deque



N = int(input())

es = [[] for _ in range(N)]



for _ in range(N - 1):

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

    u -= 1

    v -= 1

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

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



clr = [None] * N

clr[0] = 0



dq = deque()

dq.append(0)



while dq:

    v = dq.popleft()

    for nv, w in es[v]:

        if clr[nv] is not None:

            continue

        clr[nv] = (clr[v] + w) % 2

        dq.append(nv)

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

from collections import deque



n = int(input())



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

for _ in range(n - 1):

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

    u -= 1

    v -= 1

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

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



s = 0

ans = [None] * n

ans[s] = 0



dq = deque()

dq.append(s)



while dq:

    v = dq.popleft()

    for nv, w in es[v]:

        if ans[nv] is None:

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

            dq.append(nv)

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

from collections import deque

N = int(input())
es = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    es[u].append((v, w))
    es[v].append((u, w))
clr = [None] * N
clr[0] = 0
dq = deque()
dq.append(0)
while dq:
    v = dq.popleft()
    for nv, w in es[v]:
        if clr[nv] is not None:
            continue
        clr[nv] = (clr[v] + w) % 2
        dq.append(nv)
print(*clr, sep="\n")

from collections import deque

n = int(input())
es = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    es[u].append((v, w))
    es[v].append((u, w))
s = 0
ans = [None] * n
ans[s] = 0
dq = deque()
dq.append(s)
while dq:
    v = dq.popleft()
    for nv, w in es[v]:
        if ans[nv] is None:
            ans[nv] = (ans[v] + w) % 2
            dq.append(nv)
print(*ans, sep="\n")

-N = int(input()) -es = [[] for _ in range(N)] -for _ in range(N - 1): +n = int(input()) +es = [[] for _ in range(n)] +for _ in range(n - 1): -clr = [None] * N -clr[0] = 0 +s = 0 +ans = [None] * n +ans[s] = 0 -dq.append(0) +dq.append(s) -        if clr[nv] is not None: -            continue -        clr[nv] = (clr[v] + w) % 2 -        dq.append(nv) -print(*clr, sep="\n") +        if ans[nv] is None: +            ans[nv] = (ans[v] + w) % 2 +            dq.append(nv) +print(*ans, sep="\n")