import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 5)



def dfs(v, p, c):

    color[v] = c

    for e in graph[v]:

        if e[0] == p: continue

        if e[1] % 2: dfs(e[0], v, 1-c)

        else: dfs(e[0], v, c)





n = int(eval(input()))

color = [-1] * n

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



for _ in range(n-1):

    u, v, w = [int(x) for x in input().split()]

    u, v = u-1, v-1

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

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



dfs(0, -1, 1)

for c in color: print(c)
import sys

input = sys.stdin.readline



def dfs(s):

    stack = [(s, -1, 1)]

    while(len(stack)):

        v, p, c = stack[-1]

        stack.pop()

        color[v] = c

        for e in graph[v]:

            if e[0] == p: continue

            stack.append((e[0], v, abs(c - e[1] % 2)))





n = int(eval(input()))

color = [-1] * n

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



for _ in range(n-1):

    u, v, w = [int(x) for x in input().split()]

    u, v = u-1, v-1

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

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



dfs(0)

for c in color: print(c)
import sys

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


def dfs(v, p, c):
    color[v] = c
    for e in graph[v]:
        if e[0] == p:
            continue
        if e[1] % 2:
            dfs(e[0], v, 1 - c)
        else:
            dfs(e[0], v, c)


n = int(eval(input()))
color = [-1] * n
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = [int(x) for x in input().split()]
    u, v = u - 1, v - 1
    graph[u].append((v, w))
    graph[v].append((u, w))
dfs(0, -1, 1)
for c in color:
    print(c)

import sys

input = sys.stdin.readline


def dfs(s):
    stack = [(s, -1, 1)]
    while len(stack):
        v, p, c = stack[-1]
        stack.pop()
        color[v] = c
        for e in graph[v]:
            if e[0] == p:
                continue
            stack.append((e[0], v, abs(c - e[1] % 2)))


n = int(eval(input()))
color = [-1] * n
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = [int(x) for x in input().split()]
    u, v = u - 1, v - 1
    graph[u].append((v, w))
    graph[v].append((u, w))
dfs(0)
for c in color:
    print(c)

-sys.setrecursionlimit(10**5) -def dfs(v, p, c): -    color[v] = c -    for e in graph[v]: -        if e[0] == p: -            continue -        if e[1] % 2: -            dfs(e[0], v, 1 - c) -        else: -            dfs(e[0], v, c) +def dfs(s): +    stack = [(s, -1, 1)] +    while len(stack): +        v, p, c = stack[-1] +        stack.pop() +        color[v] = c +        for e in graph[v]: +            if e[0] == p: +                continue +            stack.append((e[0], v, abs(c - e[1] % 2))) -dfs(0, -1, 1) +dfs(0)