import sys

sys.setrecursionlimit(10**6)



n = int(eval(input()))

edges = [[int(i) for i in input().split()] for _ in range(n - 1)]



BLACK = 1

WHITE = 0

UNKNOWN = -1



import sys

if n == 1:

    print(BLACK)

    sys.exit(0)



colors = [UNKNOWN] * (n + 1)



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

for e in edges:

    graph[e[0]].append((e[1], e[2]))

    graph[e[1]].append((e[0], e[2]))



def dfs(graph, colors, current_point, current_color):

    colors[current_point] = current_color



    for next_point_info in graph[current_point]:

        if colors[next_point_info[0]] != UNKNOWN:

            continue

        if (next_point_info[1] % 2 == 0):

            next_color = current_color

        else:

            next_color = 1 - current_color

        dfs(graph, colors, next_point_info[0], next_color)



dfs(graph, colors, 1, BLACK)

for c in colors[1:]:

    print(c)

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



n = int(eval(input()))

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

for _ in range(n - 1):

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

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

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



def dfs(graph, queue, color):

    is_bigraph = True

    while queue:

        current = queue.pop()

        current_color = color[current]



        for _next, dist in graph[current]:

            if color[_next] != - 1:

                if color[_next] != (color[current] + dist) % 2:

                    is_bigraph = False

            else:

                color[_next] = (color[current] + dist) % 2

                queue.append(_next)



    return is_bigraph



queue = [1]

color = [-1] + [-1] * n

color[1] = 0

if not dfs(graph, queue, color):

    print('Something wrong')

    sys.exit(1)



for c in color[1:]:

    print(c)

import sys

sys.setrecursionlimit(10**6)
n = int(eval(input()))
edges = [[int(i) for i in input().split()] for _ in range(n - 1)]
BLACK = 1
WHITE = 0
UNKNOWN = -1
import sys

if n == 1:
    print(BLACK)
    sys.exit(0)
colors = [UNKNOWN] * (n + 1)
graph = [[] for _ in range(n + 1)]
for e in edges:
    graph[e[0]].append((e[1], e[2]))
    graph[e[1]].append((e[0], e[2]))


def dfs(graph, colors, current_point, current_color):
    colors[current_point] = current_color
    for next_point_info in graph[current_point]:
        if colors[next_point_info[0]] != UNKNOWN:
            continue
        if next_point_info[1] % 2 == 0:
            next_color = current_color
        else:
            next_color = 1 - current_color
        dfs(graph, colors, next_point_info[0], next_color)


dfs(graph, colors, 1, BLACK)
for c in colors[1:]:
    print(c)

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(eval(input()))
graph = [0] + [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    graph[u].append((v, w))
    graph[v].append((u, w))


def dfs(graph, queue, color):
    is_bigraph = True
    while queue:
        current = queue.pop()
        current_color = color[current]
        for _next, dist in graph[current]:
            if color[_next] != -1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)
    return is_bigraph


queue = [1]
color = [-1] + [-1] * n
color[1] = 0
if not dfs(graph, queue, color):
    print("Something wrong")
    sys.exit(1)
for c in color[1:]:
    print(c)

-sys.setrecursionlimit(10**6) +input = sys.stdin.readline +sys.setrecursionlimit(10**7) -edges = [[int(i) for i in input().split()] for _ in range(n - 1)] -BLACK = 1 -WHITE = 0 -UNKNOWN = -1 -import sys - -if n == 1: -    print(BLACK) -    sys.exit(0) -colors = [UNKNOWN] * (n + 1) -graph = [[] for _ in range(n + 1)] -for e in edges: -    graph[e[0]].append((e[1], e[2])) -    graph[e[1]].append((e[0], e[2])) +graph = [0] + [[] for _ in range(n)] +for _ in range(n - 1): +    u, v, w = list(map(int, input().split())) +    graph[u].append((v, w)) +    graph[v].append((u, w)) -def dfs(graph, colors, current_point, current_color): -    colors[current_point] = current_color -    for next_point_info in graph[current_point]: -        if colors[next_point_info[0]] != UNKNOWN: -            continue -        if next_point_info[1] % 2 == 0: -            next_color = current_color -        else: -            next_color = 1 - current_color -        dfs(graph, colors, next_point_info[0], next_color) +def dfs(graph, queue, color): +    is_bigraph = True +    while queue: +        current = queue.pop() +        current_color = color[current] +        for _next, dist in graph[current]: +            if color[_next] != -1: +                if color[_next] != (color[current] + dist) % 2: +                    is_bigraph = False +            else: +                color[_next] = (color[current] + dist) % 2 +                queue.append(_next) +    return is_bigraph -dfs(graph, colors, 1, BLACK) -for c in colors[1:]: +queue = [1] +color = [-1] + [-1] * n +color[1] = 0 +if not dfs(graph, queue, color): +    print("Something wrong") +    sys.exit(1) +for c in color[1:]: