from collections import deque

n = int(input())

color = [-1]*(n+1)
rel = [{} for i in range(n+1)]

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

def f(n):
    color[n] = 0
    stack = deque()
    stack.append(n)
    while stack:
        new = stack.pop()
        for ver in rel[new]:
            if color[ver] == -1:
                color[ver] = 1-color[new] if rel[new][ver]&1 else color[new]
                stack.append(ver)

for i in range(1, n+1):
    if color[i] != -1: continue
    f(n)

print(*color[1:], sep="\n") from collections import deque n = int(input()) n int(input()) int input() input color = [-1]*(n+1) color [-1]*(n+1) [-1] -1 n+1 n 1 {} 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) {} rel = [{} for i in range(n+1)] rel [{} for i in range(n+1)] for i in range(n-1):
    u, v, w = map(int, input().split())
    rel[u][v] = rel[v][u] = w 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 rel[u][v] = rel[v][u] = w rel[u][v] [u] rel u v w = rel[v][u] = w rel[v][u] [v] rel v u w def f(n):
    color[n] = 0
    stack = deque()
    stack.append(n)
    while stack:
        new = stack.pop()
        for ver in rel[new]:
            if color[ver] == -1:
                color[ver] = 1-color[new] if rel[new][ver]&1 else color[new]
                stack.append(ver) f color[n] = 0 color[n] color n 0 stack = deque() stack deque() deque stack.append(n) stack.append stack append n while stack:
        new = stack.pop()
        for ver in rel[new]:
            if color[ver] == -1:
                color[ver] = 1-color[new] if rel[new][ver]&1 else color[new]
                stack.append(ver) stack new = stack.pop() new stack.pop() stack.pop stack pop for ver in rel[new]:
            if color[ver] == -1:
                color[ver] = 1-color[new] if rel[new][ver]&1 else color[new]
                stack.append(ver) ver rel[new] rel new if color[ver] == -1:
                color[ver] = 1-color[new] if rel[new][ver]&1 else color[new]
                stack.append(ver) color[ver] == -1 color[ver] color ver -1 color[ver] = 1-color[new] if rel[new][ver]&1 else color[new] color[ver] color ver 1-color[new] if rel[new][ver]&1 else color[new] rel[new][ver]&1 rel[new][ver] [new] rel new ver 1 1-color[new] 1 color[new] color new color[new] color new stack.append(ver) stack.append stack append ver n n for i in range(1, n+1):
    if color[i] != -1: continue
    f(n) i range(1, n+1) range 1 n+1 n 1 if color[i] != -1: continue
     color[i] != -1 color[i] color i -1 f(n) f n print(*color[1:], sep="\n") print *color[1:] color[1:] color 1: 1 sep="\n" sep "\n" u, v, w = map(int, input().split()) map(int, input().split()) u def f(n):
    color[n] = 0
    stack = deque()
    stack.append(n)
    while stack:
        new = stack.pop()
        for ver in rel[new]:
            if color[ver] == -1:
                color[ver] = 1-color[new] if rel[new][ver]&1 else color[new]
                stack.append(ver) def f(n):
    color[n] = 0
    stack = deque()
    stack.append(n)
    while stack:
        new = stack.pop()
        for ver in rel[new]:
            if color[ver] == -1:
                color[ver] = 1-color[new] if rel[new][ver]&1 else color[new]
                stack.append(ver) f rel = [{} for i in range(n+1)] [{} for i in range(n+1)] rel color = [-1]*(n+1) [-1]*(n+1) color w = map(int, input().split()) map(int, input().split()) w v, w = map(int, input().split()) map(int, input().split()) v n = int(input()) int(input()) n
from collections import deque

n = int(input())

color = [-1]*(n+1)
rel = [{} for i in range(n+1)]

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

def f(n):
    color[n] = 0
    stack = deque()
    stack.append(n)
    while stack:
        new = stack.pop()
        for ver in rel[new]:
            if color[ver] == -1:
                color[ver] = 1-color[new] if rel[new][ver]&1 else color[new]
                stack.append(ver)

for i in range(1, n+1):
    if color[i] != -1: continue
    f(n)

print(*color[1:], sep="\n")
