from queue import Queue
N = int(input())
G = [[] for _ in range(N)]
C = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    C[a].append(w)
    G[b].append(a)
    C[b].append(w)
ans = [-1] * N
ans[0] = 0
que = Queue()
que.put(0)
while not que.empty():
    v = que.get()
    l = len(G[v])
    for i in range(l):
        u = G[v][i]
        w = C[v][i]
        if ans[u] != -1:
            continue
        ans[u] = (ans[v] + w) % 2
        que.put(u)
print(*ans, sep='\n') from queue import Queue N = int(input()) N int(input()) int input() input [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] G = [[] for _ in range(N)] G [[] for _ in range(N)] [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] C = [[] for _ in range(N)] C [[] for _ in range(N)] for _ in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    C[a].append(w)
    G[b].append(a)
    C[b].append(w) _ range(N-1) range N-1 N 1 a, b, w = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b w a -= 1 a 1 b -= 1 b 1 G[a].append(b) [a].append [a] G a append b C[a].append(w) [a].append [a] C a append w G[b].append(a) [b].append [b] G b append a C[b].append(w) [b].append [b] C b append w ans = [-1] * N ans [-1] * N [-1] -1 N ans[0] = 0 ans[0] ans 0 0 que = Queue() que Queue() Queue que.put(0) que.put que put 0 while not que.empty():
    v = que.get()
    l = len(G[v])
    for i in range(l):
        u = G[v][i]
        w = C[v][i]
        if ans[u] != -1:
            continue
        ans[u] = (ans[v] + w) % 2
        que.put(u) not que.empty() que.empty() que.empty que empty v = que.get() v que.get() que.get que get l = len(G[v]) l len(G[v]) len G[v] G v for i in range(l):
        u = G[v][i]
        w = C[v][i]
        if ans[u] != -1:
            continue
        ans[u] = (ans[v] + w) % 2
        que.put(u) i range(l) range l u = G[v][i] u G[v][i] [v] G v i w = C[v][i] w C[v][i] [v] C v i if ans[u] != -1:
            continue
         ans[u] != -1 ans[u] ans u -1 continue ans[u] = (ans[v] + w) % 2 ans[u] ans u (ans[v] + w) % 2 ans[v] + w ans[v] ans v w 2 que.put(u) que.put que put u print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' v = que.get() que.get() v b, w = map(int, input().split()) map(int, input().split()) b l = len(G[v]) len(G[v]) l G = [[] for _ in range(N)] [[] for _ in range(N)] G b -= 1 1 b u = G[v][i] G[v][i] u w = C[v][i] C[v][i] w N = int(input()) int(input()) N C = [[] for _ in range(N)] [[] for _ in range(N)] C ans = [-1] * N [-1] * N ans a -= 1 1 a w = map(int, input().split()) map(int, input().split()) w que = Queue() Queue() que a, b, w = map(int, input().split()) map(int, input().split()) a
from queue import Queue
N = int(input())
G = [[] for _ in range(N)]
C = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    C[a].append(w)
    G[b].append(a)
    C[b].append(w)
ans = [-1] * N
ans[0] = 0
que = Queue()
que.put(0)
while not que.empty():
    v = que.get()
    l = len(G[v])
    for i in range(l):
        u = G[v][i]
        w = C[v][i]
        if ans[u] != -1:
            continue
        ans[u] = (ans[v] + w) % 2
        que.put(u)
print(*ans, sep='\n')