import sys

sys.setrecursionlimit(10**6)



N = int(eval(input()))

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



for _ in range(N-1):

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

    if w&1:

        edges[u-1].append((v-1, -1))

        edges[v-1].append((u-1, -1))

    else:

        edges[u-1].append((v-1, 1))

        edges[v-1].append((u-1, 1))



colors = [None] * N



def set_color(x, c):

    colors[x] = c

    for y, sgn in edges[x]:

        if colors[y] == None:

            set_color(y, c*sgn)



set_color(0, 1)

for z in colors:

    print(((z+1)//2))

# coding: utf-8

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N = ir()

graph = [[] for _ in range(N+1)] # 1-indexed

for _ in range(N-1):

    a, b, w = lr()

    graph[a].append((b, w%2))

    graph[b].append((a, w%2))



color = [None] * (N+1)

color[1] = 0

root = 1

parent = [0] * (N+1)

stack = [(root, 0)]

while stack:

    cur, c = stack.pop()

    for next, weight in graph[cur]:

        if next == parent[cur]:

            continue

        parent[next] = cur

        if weight == 0:

            color[next] = c

        else:

            color[next] = 1 - c

        stack.append((next, color[next]))



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

import sys

sys.setrecursionlimit(10**6)
N = int(eval(input()))
edges = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    if w & 1:
        edges[u - 1].append((v - 1, -1))
        edges[v - 1].append((u - 1, -1))
    else:
        edges[u - 1].append((v - 1, 1))
        edges[v - 1].append((u - 1, 1))
colors = [None] * N


def set_color(x, c):
    colors[x] = c
    for y, sgn in edges[x]:
        if colors[y] == None:
            set_color(y, c * sgn)


set_color(0, 1)
for z in colors:
    print(((z + 1) // 2))

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
graph = [[] for _ in range(N + 1)]  # 1-indexed
for _ in range(N - 1):
    a, b, w = lr()
    graph[a].append((b, w % 2))
    graph[b].append((a, w % 2))
color = [None] * (N + 1)
color[1] = 0
root = 1
parent = [0] * (N + 1)
stack = [(root, 0)]
while stack:
    cur, c = stack.pop()
    for next, weight in graph[cur]:
        if next == parent[cur]:
            continue
        parent[next] = cur
        if weight == 0:
            color[next] = c
        else:
            color[next] = 1 - c
        stack.append((next, color[next]))
print(*color[1:], sep="\n")

+# coding: utf-8 -sys.setrecursionlimit(10**6) -N = int(eval(input())) -edges = [[] for _ in range(N)] +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N = ir() +graph = [[] for _ in range(N + 1)]  # 1-indexed -    u, v, w = list(map(int, input().split())) -    if w & 1: -        edges[u - 1].append((v - 1, -1)) -        edges[v - 1].append((u - 1, -1)) -    else: -        edges[u - 1].append((v - 1, 1)) -        edges[v - 1].append((u - 1, 1)) -colors = [None] * N - - -def set_color(x, c): -    colors[x] = c -    for y, sgn in edges[x]: -        if colors[y] == None: -            set_color(y, c * sgn) - - -set_color(0, 1) -for z in colors: -    print(((z + 1) // 2)) +    a, b, w = lr() +    graph[a].append((b, w % 2)) +    graph[b].append((a, w % 2)) +color = [None] * (N + 1) +color[1] = 0 +root = 1 +parent = [0] * (N + 1) +stack = [(root, 0)] +while stack: +    cur, c = stack.pop() +    for next, weight in graph[cur]: +        if next == parent[cur]: +            continue +        parent[next] = cur +        if weight == 0: +            color[next] = c +        else: +            color[next] = 1 - c +        stack.append((next, color[next])) +print(*color[1:], sep="\n")