import sys

sys.setrecursionlimit(10**6)



N = int(eval(input()))



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





for _ in range(N-1):

  v1,v2,w = [int(x) for x in input().split()]

  if w&1:

    edge[v1].append((v2,-1))

    edge[v2].append((v1,-1))

  else:

    edge[v1].append((v2,1))

    edge[v2].append((v1,1))



color = [None] * (N+1)



def set_color(v,c):

  color[v] = c

  for x,sgn in edge[v]:

    if color[x] is None:

      set_color(x,sgn*c)

      

set_color(1,1)



for x in color[1:]:

  print(((x+1)//2))
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N = int(readline())

m = list(map(int,read().split()))

UVW = list(zip(m,m,m))



# 木が保証されているので、必ず実現できる



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

for u,v,w in UVW:

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

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



color = [0] * (N+1)

stack = [1]

parent = [0] * (N+1)

while stack:

    x = stack.pop()

    for y,w in graph[x]:

        if y == parent[x]:

            continue

        parent[y] = x

        color[y] = color[x]^(w&1)

        stack.append(y)



print(('\n'.join(map(str,color[1:]))))
import sys

sys.setrecursionlimit(10**6)
N = int(eval(input()))
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    v1, v2, w = [int(x) for x in input().split()]
    if w & 1:
        edge[v1].append((v2, -1))
        edge[v2].append((v1, -1))
    else:
        edge[v1].append((v2, 1))
        edge[v2].append((v1, 1))
color = [None] * (N + 1)


def set_color(v, c):
    color[v] = c
    for x, sgn in edge[v]:
        if color[x] is None:
            set_color(x, sgn * c)


set_color(1, 1)
for x in color[1:]:
    print(((x + 1) // 2))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = list(map(int, read().split()))
UVW = list(zip(m, m, m))
# 木が保証されているので、必ず実現できる
graph = [[] for _ in range(N + 1)]
for u, v, w in UVW:
    graph[u].append((v, w))
    graph[v].append((u, w))
color = [0] * (N + 1)
stack = [1]
parent = [0] * (N + 1)
while stack:
    x = stack.pop()
    for y, w in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        color[y] = color[x] ^ (w & 1)
        stack.append(y)
print(("\n".join(map(str, color[1:]))))

-sys.setrecursionlimit(10**6) -N = int(eval(input())) -edge = [[] for _ in range(N + 1)] -for _ in range(N - 1): -    v1, v2, w = [int(x) for x in input().split()] -    if w & 1: -        edge[v1].append((v2, -1)) -        edge[v2].append((v1, -1)) -    else: -        edge[v1].append((v2, 1)) -        edge[v2].append((v1, 1)) -color = [None] * (N + 1) - - -def set_color(v, c): -    color[v] = c -    for x, sgn in edge[v]: -        if color[x] is None: -            set_color(x, sgn * c) - - -set_color(1, 1) -for x in color[1:]: -    print(((x + 1) // 2)) +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +N = int(readline()) +m = list(map(int, read().split())) +UVW = list(zip(m, m, m)) +# 木が保証されているので、必ず実現できる +graph = [[] for _ in range(N + 1)] +for u, v, w in UVW: +    graph[u].append((v, w)) +    graph[v].append((u, w)) +color = [0] * (N + 1) +stack = [1] +parent = [0] * (N + 1) +while stack: +    x = stack.pop() +    for y, w in graph[x]: +        if y == parent[x]: +            continue +        parent[y] = x +        color[y] = color[x] ^ (w & 1) +        stack.append(y) +print(("\n".join(map(str, color[1:]))))