from collections import deque

n = int(input())

distance = [-1] * n

edge = [dict() for _ in range(n)]

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

D = deque([0])
distance[0] = 0

while D:
    now = D.popleft()
    for i in edge[now]:
        if distance[i] == -1:
            distance[i] = (distance[now] + edge[now][i]) % 2
            D.append(i)

for i in distance:
    print(i) from collections import deque n = int(input()) n int(input()) int input() input distance = [-1] * n distance [-1] * n [-1] -1 n dict() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) dict() dict edge = [dict() for _ in range(n)] edge [dict() for _ in range(n)] for _ in range(n-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    edge[u][v] = w
    edge[v][u] = w _ 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 u, v = u-1, v-1 u u-1 u 1 v v-1 v 1 edge[u][v] = w edge[u][v] [u] edge u v w edge[v][u] = w edge[v][u] [v] edge v u w D = deque([0]) D deque([0]) deque [0] 0 distance[0] = 0 distance[0] distance 0 0 while D:
    now = D.popleft()
    for i in edge[now]:
        if distance[i] == -1:
            distance[i] = (distance[now] + edge[now][i]) % 2
            D.append(i) D now = D.popleft() now D.popleft() D.popleft D popleft for i in edge[now]:
        if distance[i] == -1:
            distance[i] = (distance[now] + edge[now][i]) % 2
            D.append(i) i edge[now] edge now if distance[i] == -1:
            distance[i] = (distance[now] + edge[now][i]) % 2
            D.append(i) distance[i] == -1 distance[i] distance i -1 distance[i] = (distance[now] + edge[now][i]) % 2 distance[i] distance i (distance[now] + edge[now][i]) % 2 distance[now] + edge[now][i] distance[now] distance now edge[now][i] [now] edge now i 2 D.append(i) D.append D append i for i in distance:
    print(i) i distance print(i) print i v, w = map(int, input().split()) map(int, input().split()) v now = D.popleft() D.popleft() now edge = [dict() for _ in range(n)] [dict() for _ in range(n)] edge D = deque([0]) deque([0]) D n = int(input()) int(input()) n v = u-1, v-1 v-1 v u, v = u-1, v-1 u-1 u distance = [-1] * n [-1] * n distance u, v, w = map(int, input().split()) map(int, input().split()) u w = map(int, input().split()) map(int, input().split()) w
from collections import deque

n = int(input())

distance = [-1] * n

edge = [dict() for _ in range(n)]

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

D = deque([0])
distance[0] = 0

while D:
    now = D.popleft()
    for i in edge[now]:
        if distance[i] == -1:
            distance[i] = (distance[now] + edge[now][i]) % 2
            D.append(i)

for i in distance:
    print(i)