import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    edges[u-1].append((w, v-1))
    edges[v-1].append((w, u-1))

next_v = deque([(0, 0)])
color = [-1]*n
while next_v:
    d, v = next_v.popleft()
    color[v] = d & 1
    for d2, v2 in edges[v]:
        if color[v2] != -1:
            continue
        next_v.append((d+d2, v2))
print(*color, sep='\n') import sys sys from collections import deque input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 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) [] edges = [[]for _ in range(n)] edges [[]for _ in range(n)] for _ in range(n-1):
    u, v, w = map(int, input().split())
    edges[u-1].append((w, v-1))
    edges[v-1].append((w, u-1)) _ 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 edges[u-1].append((w, v-1)) [u-1].append [u-1] edges u-1 u 1 append (w, v-1) w v-1 v 1 edges[v-1].append((w, u-1)) [v-1].append [v-1] edges v-1 v 1 append (w, u-1) w u-1 u 1 next_v = deque([(0, 0)]) next_v deque([(0, 0)]) deque [(0, 0)] (0, 0) 0 0 color = [-1]*n color [-1]*n [-1] -1 n while next_v:
    d, v = next_v.popleft()
    color[v] = d & 1
    for d2, v2 in edges[v]:
        if color[v2] != -1:
            continue
        next_v.append((d+d2, v2)) next_v d, v = next_v.popleft() d next_v.popleft() next_v.popleft next_v popleft v color[v] = d & 1 color[v] color v d & 1 d 1 for d2, v2 in edges[v]:
        if color[v2] != -1:
            continue
        next_v.append((d+d2, v2)) d2 v2 edges[v] edges v if color[v2] != -1:
            continue
         color[v2] != -1 color[v2] color v2 -1 continue next_v.append((d+d2, v2)) next_v.append next_v append (d+d2, v2) d+d2 d d2 v2 print(*color, sep='\n') print *color color sep='\n' sep '\n' w = map(int, input().split()) map(int, input().split()) w edges = [[]for _ in range(n)] [[]for _ in range(n)] edges d, v = next_v.popleft() next_v.popleft() d color = [-1]*n [-1]*n color v, w = map(int, input().split()) map(int, input().split()) v u, v, w = map(int, input().split()) map(int, input().split()) u v = next_v.popleft() next_v.popleft() v next_v = deque([(0, 0)]) deque([(0, 0)]) next_v input = sys.stdin.readline sys.stdin.readline input n = int(input()) int(input()) n
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    edges[u-1].append((w, v-1))
    edges[v-1].append((w, u-1))

next_v = deque([(0, 0)])
color = [-1]*n
while next_v:
    d, v = next_v.popleft()
    color[v] = d & 1
    for d2, v2 in edges[v]:
        if color[v2] != -1:
            continue
        next_v.append((d+d2, v2))
print(*color, sep='\n')
