from collections import deque
n = int(input())
to = [[] for i in range(n)]
col = [0] + [-1] * (n - 1)

for i in range(n - 1):
    u, v, w = map(int, input().split())
    to[u - 1].append((v - 1, w % 2))
    to[v - 1].append((u - 1, w % 2))

search = deque([0])
while search:
    v = search.popleft()
    for nv, nw in to[v]:
        if col[nv] != -1:
            continue
        col[nv] = (col[v] + nw) % 2
        search.append(nv)
print(*col, sep='\n') from collections import deque n = int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] to = [[] for i in range(n)] to [[] for i in range(n)] col = [0] + [-1] * (n - 1) col [0] + [-1] * (n - 1) [0] 0 [-1] * (n - 1) [-1] -1 n - 1 n 1 for i in range(n - 1):
    u, v, w = map(int, input().split())
    to[u - 1].append((v - 1, w % 2))
    to[v - 1].append((u - 1, 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 to[u - 1].append((v - 1, w % 2)) [u - 1].append [u - 1] to u - 1 u 1 append (v - 1, w % 2) v - 1 v 1 w % 2 w 2 to[v - 1].append((u - 1, w % 2)) [v - 1].append [v - 1] to v - 1 v 1 append (u - 1, w % 2) u - 1 u 1 w % 2 w 2 search = deque([0]) search deque([0]) deque [0] 0 while search:
    v = search.popleft()
    for nv, nw in to[v]:
        if col[nv] != -1:
            continue
        col[nv] = (col[v] + nw) % 2
        search.append(nv) search v = search.popleft() v search.popleft() search.popleft search popleft for nv, nw in to[v]:
        if col[nv] != -1:
            continue
        col[nv] = (col[v] + nw) % 2
        search.append(nv) nv nw to[v] to v if col[nv] != -1:
            continue
         col[nv] != -1 col[nv] col nv -1 continue col[nv] = (col[v] + nw) % 2 col[nv] col nv (col[v] + nw) % 2 col[v] + nw col[v] col v nw 2 search.append(nv) search.append search append nv print(*col, sep='\n') print *col col sep='\n' sep '\n' v, w = map(int, input().split()) map(int, input().split()) v u, v, w = map(int, input().split()) map(int, input().split()) u w = map(int, input().split()) map(int, input().split()) w search = deque([0]) deque([0]) search v = search.popleft() search.popleft() v to = [[] for i in range(n)] [[] for i in range(n)] to col = [0] + [-1] * (n - 1) [0] + [-1] * (n - 1) col n = int(input()) int(input()) n
from collections import deque
n = int(input())
to = [[] for i in range(n)]
col = [0] + [-1] * (n - 1)

for i in range(n - 1):
    u, v, w = map(int, input().split())
    to[u - 1].append((v - 1, w % 2))
    to[v - 1].append((u - 1, w % 2))

search = deque([0])
while search:
    v = search.popleft()
    for nv, nw in to[v]:
        if col[nv] != -1:
            continue
        col[nv] = (col[v] + nw) % 2
        search.append(nv)
print(*col, sep='\n')