N = int(eval(input()))

import sys

sys.setrecursionlimit(90000)



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

for _ in range(N-1):

    a, b, c = list(map(int, input().split()))

    graph[a-1].append((b-1, c))

    graph[b-1].append((a-1, c))



color = [-1 for _ in range(N)]

def dfs(p, c, color):

    color[p] = c

    cinv = 0 if c == 1 else 1

    for q, d in graph[p]:

        if color[q] != -1:

            continue

        if d % 2 == 1:

            color = dfs(q, cinv, color)

        else:

            color = dfs(q, c, color)

    return color



A = dfs(0, 0, color)

for a in A:

    print(a)
import sys

input = sys.stdin.readline





N = int(input())

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

for _ in range(N-1):

    a, b, w = map(int, input().split())

    graph[a-1].append((b-1, w))

    graph[b-1].append((a-1, w))



def dfs(s):

    Ind = [0]*N

    stack = [s]

    Color = [0]*N

    while stack:

        p = stack[-1]

        if Ind[p] == len(graph[p]):

            stack.pop()

        elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]][0]:

            Ind[p] += 1

        else:

            ch, w = graph[p][Ind[p]]

            Ind[p] += 1

            stack.append(ch)

            Color[ch] = Color[p]^(w%2)

    return Color



Color = dfs(0)

print(*Color, sep="\n")

N = int(eval(input()))
import sys

sys.setrecursionlimit(90000)
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    graph[a - 1].append((b - 1, c))
    graph[b - 1].append((a - 1, c))
color = [-1 for _ in range(N)]


def dfs(p, c, color):
    color[p] = c
    cinv = 0 if c == 1 else 1
    for q, d in graph[p]:
        if color[q] != -1:
            continue
        if d % 2 == 1:
            color = dfs(q, cinv, color)
        else:
            color = dfs(q, c, color)
    return color


A = dfs(0, 0, color)
for a in A:
    print(a)

import sys

input = sys.stdin.readline
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, w = map(int, input().split())
    graph[a - 1].append((b - 1, w))
    graph[b - 1].append((a - 1, w))


def dfs(s):
    Ind = [0] * N
    stack = [s]
    Color = [0] * N
    while stack:
        p = stack[-1]
        if Ind[p] == len(graph[p]):
            stack.pop()
        elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]][0]:
            Ind[p] += 1
        else:
            ch, w = graph[p][Ind[p]]
            Ind[p] += 1
            stack.append(ch)
            Color[ch] = Color[p] ^ (w % 2)
    return Color


Color = dfs(0)
print(*Color, sep="\n")

-N = int(eval(input())) -sys.setrecursionlimit(90000) +input = sys.stdin.readline +N = int(input()) -    a, b, c = list(map(int, input().split())) -    graph[a - 1].append((b - 1, c)) -    graph[b - 1].append((a - 1, c)) -color = [-1 for _ in range(N)] +    a, b, w = map(int, input().split()) +    graph[a - 1].append((b - 1, w)) +    graph[b - 1].append((a - 1, w)) -def dfs(p, c, color): -    color[p] = c -    cinv = 0 if c == 1 else 1 -    for q, d in graph[p]: -        if color[q] != -1: -            continue -        if d % 2 == 1: -            color = dfs(q, cinv, color) +def dfs(s): +    Ind = [0] * N +    stack = [s] +    Color = [0] * N +    while stack: +        p = stack[-1] +        if Ind[p] == len(graph[p]): +            stack.pop() +        elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]][0]: +            Ind[p] += 1 -            color = dfs(q, c, color) -    return color +            ch, w = graph[p][Ind[p]] +            Ind[p] += 1 +            stack.append(ch) +            Color[ch] = Color[p] ^ (w % 2) +    return Color -A = dfs(0, 0, color) -for a in A: -    print(a) +Color = dfs(0) +print(*Color, sep="\n")