from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((u, v, w % 2))
    E[v].append((v, u, w % 2))
dfs = deque(E[1])
while dfs:
    p = (dfs.popleft())
    f, t, w = p
    if ans[t] != -1:
        continue
    if w == 0:
        ans[t] = ans[f]
    else:
        ans[t] = 0 if ans[f] else 1
    for i in E[t]:
        dfs.append(i)
for i in ans[1:]:
    print(i) from collections import deque N = int(input()) N int(input()) int input() input [] for i in range(N + 1) for i in range(N + 1) i range(N + 1) range N + 1 N 1 for i in range(N + 1) [] E = [[] for i in range(N + 1)] E [[] for i in range(N + 1)] ans = [-1]*(N+1) ans [-1]*(N+1) [-1] -1 N+1 N 1 ans[1] = 0 ans[1] ans 1 0 for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((u, v, w % 2))
    E[v].append((v, u, w % 2)) i range(N - 1) range N - 1 N 1 u, v, w = map(int, input().split((' '))) u map(int, input().split((' '))) map int input().split((' ')) ().split () input split ' ' v w E[u].append((u, v, w % 2)) [u].append [u] E u append (u, v, w % 2) u v w % 2 w 2 E[v].append((v, u, w % 2)) [v].append [v] E v append (v, u, w % 2) v u w % 2 w 2 dfs = deque(E[1]) dfs deque(E[1]) deque E[1] E 1 while dfs:
    p = (dfs.popleft())
    f, t, w = p
    if ans[t] != -1:
        continue
    if w == 0:
        ans[t] = ans[f]
    else:
        ans[t] = 0 if ans[f] else 1
    for i in E[t]:
        dfs.append(i) dfs p = (dfs.popleft()) p dfs.popleft() dfs.popleft dfs popleft f, t, w = p f p t w if ans[t] != -1:
        continue
     ans[t] != -1 ans[t] ans t -1 continue if w == 0:
        ans[t] = ans[f]
    else:
        ans[t] = 0 if ans[f] else 1
     w == 0 w 0 ans[t] = ans[f] ans[t] ans t ans[f] ans f ans[t] = 0 if ans[f] else 1 ans[t] ans t 0 if ans[f] else 1 ans[f] ans f 0 1 for i in E[t]:
        dfs.append(i) i E[t] E t dfs.append(i) dfs.append dfs append i for i in ans[1:]:
    print(i) i ans[1:] ans 1: 1 print(i) print i v, w = map(int, input().split((' '))) map(int, input().split((' '))) v w = map(int, input().split((' '))) map(int, input().split((' '))) w w = p p w ans = [-1]*(N+1) [-1]*(N+1) ans t, w = p p t E = [[] for i in range(N + 1)] [[] for i in range(N + 1)] E dfs = deque(E[1]) deque(E[1]) dfs p = (dfs.popleft()) dfs.popleft() p f, t, w = p p f N = int(input()) int(input()) N u, v, w = map(int, input().split((' '))) map(int, input().split((' '))) u
from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((u, v, w % 2))
    E[v].append((v, u, w % 2))
dfs = deque(E[1])
while dfs:
    p = (dfs.popleft())
    f, t, w = p
    if ans[t] != -1:
        continue
    if w == 0:
        ans[t] = ans[f]
    else:
        ans[t] = 0 if ans[f] else 1
    for i in E[t]:
        dfs.append(i)
for i in ans[1:]:
    print(i)