import sys

sys.setrecursionlimit(10 ** 6)



def dfs(v):

    check[v] = True

    for u, w in T[v]:

        if check[u]:

            continue

        dist[u] = dist[v] + w

        dfs(u)



N = int(input())

T = [[] for _ in range(N+1)]

for _ in range(N-1):

    u, v, w = map(int, input().split())

    T[u].append((v, w))

    T[v].append((u, w))



dist = [0] * (N + 1)

check = [False] * (N + 1)

dfs(1)



print(*[d % 2 for d in dist[1:]], sep="\n")

import sys

sys.setrecursionlimit(10 ** 6)

input = sys.stdin.readline



def dfs(d, v, p):

    if (d & 1):

        C[v] = 1

    for w, u in E[v]:

        if u == p:

            continue

        dfs(d ^ w, u, v)



N = int(input())

C = [0] * N

E = [[] for _ in range(N)]

for i in range(N-1):

    u, v, w = map(int, input().split())

    u -= 1

    v -= 1

    E[u].append((w % 2, v))

    E[v].append((w % 2, u))

dfs(0, 0, -1)

print(*C, sep='\n')

import sys

sys.setrecursionlimit(10**6)


def dfs(v):
    check[v] = True
    for u, w in T[v]:
        if check[u]:
            continue
        dist[u] = dist[v] + w
        dfs(u)


N = int(input())
T = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    T[u].append((v, w))
    T[v].append((u, w))
dist = [0] * (N + 1)
check = [False] * (N + 1)
dfs(1)
print(*[d % 2 for d in dist[1:]], sep="\n")

import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def dfs(d, v, p):
    if d & 1:
        C[v] = 1
    for w, u in E[v]:
        if u == p:
            continue
        dfs(d ^ w, u, v)


N = int(input())
C = [0] * N
E = [[] for _ in range(N)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    E[u].append((w % 2, v))
    E[v].append((w % 2, u))
dfs(0, 0, -1)
print(*C, sep="\n")

+input = sys.stdin.readline -def dfs(v): -    check[v] = True -    for u, w in T[v]: -        if check[u]: +def dfs(d, v, p): +    if d & 1: +        C[v] = 1 +    for w, u in E[v]: +        if u == p: -        dist[u] = dist[v] + w -        dfs(u) +        dfs(d ^ w, u, v) -T = [[] for _ in range(N + 1)] -for _ in range(N - 1): +C = [0] * N +E = [[] for _ in range(N)] +for i in range(N - 1): -    T[u].append((v, w)) -    T[v].append((u, w)) -dist = [0] * (N + 1) -check = [False] * (N + 1) -dfs(1) -print(*[d % 2 for d in dist[1:]], sep="\n") +    u -= 1 +    v -= 1 +    E[u].append((w % 2, v)) +    E[v].append((w % 2, u)) +dfs(0, 0, -1) +print(*C, sep="\n")