from collections import deque

n = int(input())
tree = {i: set() for i in range(n)}
cost = {}
for _ in range(n-1):
    u, v, w = map(lambda x: int(x)-1, input().split())
    tree[u].add(v)
    tree[v].add(u)
    cost[(u, v)] = w + 1

color = [-1] * n
color[0] = 0
que = deque([0])
while que:
    now = que.popleft()
    for i in tree[now]:
        if color[i] != -1:
            continue
        if cost[(min(now, i), max(now, i))] % 2 == 0:
            color[i] = color[now]
        else:
            color[i] = color[now] ^ 1
        que.append(i)
print('\n'.join(map(str, color))) from collections import deque n = int(input()) n int(input()) int input() input i: set() for i in range(n) for i in range(n) i range(n) range n for i in range(n) i set() set tree = {i: set() for i in range(n)} tree {i: set() for i in range(n)} cost = {} cost {} for _ in range(n-1):
    u, v, w = map(lambda x: int(x)-1, input().split())
    tree[u].add(v)
    tree[v].add(u)
    cost[(u, v)] = w + 1 _ range(n-1) range n-1 n 1 u, v, w = map(lambda x: int(x)-1, input().split()) u map(lambda x: int(x)-1, input().split()) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split v w tree[u].add(v) [u].add [u] tree u add v tree[v].add(u) [v].add [v] tree v add u cost[(u, v)] = w + 1 cost[(u, v)] cost (u, v) u v w + 1 w 1 color = [-1] * n color [-1] * n [-1] -1 n color[0] = 0 color[0] color 0 0 que = deque([0]) que deque([0]) deque [0] 0 while que:
    now = que.popleft()
    for i in tree[now]:
        if color[i] != -1:
            continue
        if cost[(min(now, i), max(now, i))] % 2 == 0:
            color[i] = color[now]
        else:
            color[i] = color[now] ^ 1
        que.append(i) que now = que.popleft() now que.popleft() que.popleft que popleft for i in tree[now]:
        if color[i] != -1:
            continue
        if cost[(min(now, i), max(now, i))] % 2 == 0:
            color[i] = color[now]
        else:
            color[i] = color[now] ^ 1
        que.append(i) i tree[now] tree now if color[i] != -1:
            continue
         color[i] != -1 color[i] color i -1 continue if cost[(min(now, i), max(now, i))] % 2 == 0:
            color[i] = color[now]
        else:
            color[i] = color[now] ^ 1
         cost[(min(now, i), max(now, i))] % 2 == 0 cost[(min(now, i), max(now, i))] % 2 cost[(min(now, i), max(now, i))] cost (min(now, i), max(now, i)) min(now, i) min now i max(now, i) max now i 2 0 color[i] = color[now] color[i] color i color[now] color now color[i] = color[now] ^ 1 color[i] color i color[now] ^ 1 color[now] color now 1 que.append(i) que.append que append i print('\n'.join(map(str, color))) print '\n'.join(map(str, color)) '\n'.join '\n' join map(str, color) map str color color = [-1] * n [-1] * n color u, v, w = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) u now = que.popleft() que.popleft() now w = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) w n = int(input()) int(input()) n que = deque([0]) deque([0]) que tree = {i: set() for i in range(n)} {i: set() for i in range(n)} tree cost = {} {} cost v, w = map(lambda x: int(x)-1, input().split()) map(lambda x: int(x)-1, input().split()) v
from collections import deque

n = int(input())
tree = {i: set() for i in range(n)}
cost = {}
for _ in range(n-1):
    u, v, w = map(lambda x: int(x)-1, input().split())
    tree[u].add(v)
    tree[v].add(u)
    cost[(u, v)] = w + 1

color = [-1] * n
color[0] = 0
que = deque([0])
while que:
    now = que.popleft()
    for i in tree[now]:
        if color[i] != -1:
            continue
        if cost[(min(now, i), max(now, i))] % 2 == 0:
            color[i] = color[now]
        else:
            color[i] = color[now] ^ 1
        que.append(i)
print('\n'.join(map(str, color)))
