from collections import deque

n=int(input())

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

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

for _ in range(n-1):

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

    u-=1

    v-=1

    to[u].append(v)

    to[v].append(u)

    cost[u].append(w%2)

    cost[v].append(w%2)



color=[-1]*n

color[0]=0



q=deque()

q.append(0)

while q:

    v=q.popleft()



    for t,c in zip(to[v], cost[v]):

        if color[t]!=-1:

            continue

        color[t]=color[v]^c

        q.append(t)



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

import sys

input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)

N = int(input())

edge = [[] for _ in range(N + 1)]

for _ in range(N - 1):

    a, b, c = map(int, input().split())

    edge[a].append((b, c % 2))

    edge[b].append((a, c % 2))



root = 1

dist = [-1] * (N + 1)

dist[root] = 0

node = [root]



while node:

    s = node.pop()

    d = dist[s]

    for t, c in edge[s]:

        if dist[t] != -1:

            continue

        dist[t] = (d + c) % 2

        node.append(t)



print(*dist[1:], sep="\n")

from collections import deque

n = int(input())
to = [[] for _ in range(n)]
cost = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    to[u].append(v)
    to[v].append(u)
    cost[u].append(w % 2)
    cost[v].append(w % 2)
color = [-1] * n
color[0] = 0
q = deque()
q.append(0)
while q:
    v = q.popleft()
    for t, c in zip(to[v], cost[v]):
        if color[t] != -1:
            continue
        color[t] = color[v] ^ c
        q.append(t)
print(*color, sep="\n")

import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
N = int(input())
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    edge[a].append((b, c % 2))
    edge[b].append((a, c % 2))
root = 1
dist = [-1] * (N + 1)
dist[root] = 0
node = [root]
while node:
    s = node.pop()
    d = dist[s]
    for t, c in edge[s]:
        if dist[t] != -1:
            continue
        dist[t] = (d + c) % 2
        node.append(t)
print(*dist[1:], sep="\n")

-from collections import deque +import sys -n = int(input()) -to = [[] for _ in range(n)] -cost = [[] for _ in range(n)] -for _ in range(n - 1): -    u, v, w = map(int, input().split()) -    u -= 1 -    v -= 1 -    to[u].append(v) -    to[v].append(u) -    cost[u].append(w % 2) -    cost[v].append(w % 2) -color = [-1] * n -color[0] = 0 -q = deque() -q.append(0) -while q: -    v = q.popleft() -    for t, c in zip(to[v], cost[v]): -        if color[t] != -1: +input = sys.stdin.buffer.readline +sys.setrecursionlimit(10**7) +N = int(input()) +edge = [[] for _ in range(N + 1)] +for _ in range(N - 1): +    a, b, c = map(int, input().split()) +    edge[a].append((b, c % 2)) +    edge[b].append((a, c % 2)) +root = 1 +dist = [-1] * (N + 1) +dist[root] = 0 +node = [root] +while node: +    s = node.pop() +    d = dist[s] +    for t, c in edge[s]: +        if dist[t] != -1: -        color[t] = color[v] ^ c -        q.append(t) -print(*color, sep="\n") +        dist[t] = (d + c) % 2 +        node.append(t) +print(*dist[1:], sep="\n")