N = int(input())

edges = [list(map(int, input().split())) for _ in range(N - 1)]



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

for u, v, w in edges:

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

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



edges.sort()

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

color[1] = 0

que = [1]



while que:

    u = que.pop()

    

    for v, w in graph[u]:

        if color[v] != -1:

            continue



        if w % 2 == 0:

            color[v] = color[u]

        else:

            color[v] = color[u] ^ 1

            

        que.append(v)

        

print(*color[1:], sep='\n')







from collections import deque



N = int(input())

X = [list(map(int, input().split())) for _ in range(N - 1)]



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

for u, v, w in X:

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

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



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

colors[1] = 0

q = deque([1])

while q:

    u = q.popleft()

    for v, w in graph[u]:

        if colors[v] >= 0:

            continue



        if w % 2 == 0:

            colors[v] = colors[u]

        else:

            colors[v] = 1 - colors[u]

        q.append(v)



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

N = int(input())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N + 1)]
for u, v, w in edges:
    graph[u].append((v, w))
    graph[v].append((u, w))
edges.sort()
color = [-1] * (N + 1)
color[1] = 0
que = [1]
while que:
    u = que.pop()
    for v, w in graph[u]:
        if color[v] != -1:
            continue
        if w % 2 == 0:
            color[v] = color[u]
        else:
            color[v] = color[u] ^ 1
        que.append(v)
print(*color[1:], sep="\n")

from collections import deque

N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N + 1)]
for u, v, w in X:
    graph[u].append((v, w))
    graph[v].append((u, w))
colors = [-1] * (N + 1)
colors[1] = 0
q = deque([1])
while q:
    u = q.popleft()
    for v, w in graph[u]:
        if colors[v] >= 0:
            continue
        if w % 2 == 0:
            colors[v] = colors[u]
        else:
            colors[v] = 1 - colors[u]
        q.append(v)
print(*colors[1:], sep="\n")

+from collections import deque + -edges = [list(map(int, input().split())) for _ in range(N - 1)] +X = [list(map(int, input().split())) for _ in range(N - 1)] -for u, v, w in edges: +for u, v, w in X: -edges.sort() -color = [-1] * (N + 1) -color[1] = 0 -que = [1] -while que: -    u = que.pop() +colors = [-1] * (N + 1) +colors[1] = 0 +q = deque([1]) +while q: +    u = q.popleft() -        if color[v] != -1: +        if colors[v] >= 0: -            color[v] = color[u] +            colors[v] = colors[u] -            color[v] = color[u] ^ 1 -        que.append(v) -print(*color[1:], sep="\n") +            colors[v] = 1 - colors[u] +        q.append(v) +print(*colors[1:], sep="\n")