
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 N = int(input()) N int(input()) int input() input list(map(int, input().split())) for _ in range(N - 1) for _ in range(N - 1) _ range(N - 1) range N - 1 N 1 for _ in range(N - 1) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split X = [list(map(int, input().split())) for _ in range(N - 1)] X [list(map(int, input().split())) for _ in range(N - 1)] [] for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [] graph = [[] 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)) u v w X graph[u].append((v, w)) [u].append [u] graph u append (v, w) v w graph[v].append((u, w)) [v].append [v] graph v append (u, w) u w colors = [-1] * (N + 1) colors [-1] * (N + 1) [-1] -1 N + 1 N 1 colors[1] = 0 colors[1] colors 1 0 q = deque([1]) q deque([1]) deque [1] 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) q u = q.popleft() u q.popleft() q.popleft 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) v w graph[u] graph u if colors[v] >= 0:
            continue

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

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")
