from collections import deque

N = int(input())
tree = [list(map(int, input().split())) for i in range(N-1)]

M = N-1
G = [deque([]) for i in range(N+1)]

for i in range(M):
    G[tree[i][0]].append([tree[i][1], tree[i][2]])
    G[tree[i][1]].append([tree[i][0], tree[i][2]])
    
distance = [-1] * (N+1)     

def dfs(v):
    stack = deque([v])
    distance[v] = 0
    
    while stack:   
        tmp = stack[0]
        if G[tmp]:
            w = G[tmp].popleft() 
            if distance[w[0]] < 0:
                distance[w[0]] = (distance[tmp] + w[1]) % 2
                stack.append(w[0])
        else:
            stack.popleft()
    return distance

distance = dfs(1)
for i in range(N):
    print(distance[i+1]) from collections import deque N = int(input()) N int(input()) int input() input list(map(int, input().split())) 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) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split tree = [list(map(int, input().split())) for i in range(N-1)] tree [list(map(int, input().split())) for i in range(N-1)] M = N-1 M N-1 N 1 deque([]) 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) deque([]) deque [] G = [deque([]) for i in range(N+1)] G [deque([]) for i in range(N+1)] for i in range(M):
    G[tree[i][0]].append([tree[i][1], tree[i][2]])
    G[tree[i][1]].append([tree[i][0], tree[i][2]])
     i range(M) range M G[tree[i][0]].append([tree[i][1], tree[i][2]]) [tree[i][0]].append [tree[i][0]] G tree[i][0] [i] tree i 0 append [tree[i][1], tree[i][2]] tree[i][1] [i] tree i 1 tree[i][2] [i] tree i 2 G[tree[i][1]].append([tree[i][0], tree[i][2]]) [tree[i][1]].append [tree[i][1]] G tree[i][1] [i] tree i 1 append [tree[i][0], tree[i][2]] tree[i][0] [i] tree i 0 tree[i][2] [i] tree i 2 distance = [-1] * (N+1) distance [-1] * (N+1) [-1] -1 N+1 N 1 def dfs(v):
    stack = deque([v])
    distance[v] = 0
    
    while stack:   
        tmp = stack[0]
        if G[tmp]:
            w = G[tmp].popleft() 
            if distance[w[0]] < 0:
                distance[w[0]] = (distance[tmp] + w[1]) % 2
                stack.append(w[0])
        else:
            stack.popleft()
    return distance dfs stack = deque([v]) stack deque([v]) deque [v] v distance[v] = 0 distance[v] distance v 0 while stack:   
        tmp = stack[0]
        if G[tmp]:
            w = G[tmp].popleft() 
            if distance[w[0]] < 0:
                distance[w[0]] = (distance[tmp] + w[1]) % 2
                stack.append(w[0])
        else:
            stack.popleft()
     stack tmp = stack[0] tmp stack[0] stack 0 if G[tmp]:
            w = G[tmp].popleft() 
            if distance[w[0]] < 0:
                distance[w[0]] = (distance[tmp] + w[1]) % 2
                stack.append(w[0])
        else:
            stack.popleft()
     G[tmp] G tmp w = G[tmp].popleft() w G[tmp].popleft() [tmp].popleft [tmp] G tmp popleft if distance[w[0]] < 0:
                distance[w[0]] = (distance[tmp] + w[1]) % 2
                stack.append(w[0])
         distance[w[0]] < 0 distance[w[0]] distance w[0] w 0 0 distance[w[0]] = (distance[tmp] + w[1]) % 2 distance[w[0]] distance w[0] w 0 (distance[tmp] + w[1]) % 2 distance[tmp] + w[1] distance[tmp] distance tmp w[1] w 1 2 stack.append(w[0]) stack.append stack append w[0] w 0 stack.popleft() stack.popleft stack popleft return distance distance v v distance = dfs(1) distance dfs(1) dfs 1 for i in range(N):
    print(distance[i+1]) i range(N) range N print(distance[i+1]) print distance[i+1] distance i+1 i 1 distance = dfs(1) dfs(1) distance tree = [list(map(int, input().split())) for i in range(N-1)] [list(map(int, input().split())) for i in range(N-1)] tree distance = [-1] * (N+1) [-1] * (N+1) distance def dfs(v):
    stack = deque([v])
    distance[v] = 0
    
    while stack:   
        tmp = stack[0]
        if G[tmp]:
            w = G[tmp].popleft() 
            if distance[w[0]] < 0:
                distance[w[0]] = (distance[tmp] + w[1]) % 2
                stack.append(w[0])
        else:
            stack.popleft()
    return distance def dfs(v):
    stack = deque([v])
    distance[v] = 0
    
    while stack:   
        tmp = stack[0]
        if G[tmp]:
            w = G[tmp].popleft() 
            if distance[w[0]] < 0:
                distance[w[0]] = (distance[tmp] + w[1]) % 2
                stack.append(w[0])
        else:
            stack.popleft()
    return distance dfs M = N-1 N-1 M N = int(input()) int(input()) N G = [deque([]) for i in range(N+1)] [deque([]) for i in range(N+1)] G
from collections import deque

N = int(input())
tree = [list(map(int, input().split())) for i in range(N-1)]

M = N-1
G = [deque([]) for i in range(N+1)]

for i in range(M):
    G[tree[i][0]].append([tree[i][1], tree[i][2]])
    G[tree[i][1]].append([tree[i][0], tree[i][2]])
    
distance = [-1] * (N+1)     

def dfs(v):
    stack = deque([v])
    distance[v] = 0
    
    while stack:   
        tmp = stack[0]
        if G[tmp]:
            w = G[tmp].popleft() 
            if distance[w[0]] < 0:
                distance[w[0]] = (distance[tmp] + w[1]) % 2
                stack.append(w[0])
        else:
            stack.popleft()
    return distance

distance = dfs(1)
for i in range(N):
    print(distance[i+1])