import sys,queue,math,copy,itertools,bisect,collections

sys.setrecursionlimit(10**7)

INF = 10**18

MOD = 10**9 + 7

LI = lambda : [int(x) for x in sys.stdin.readline().split()]

_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]

NI = lambda : int(sys.stdin.readline())



N = NI()

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

color = [-1] * (N+1)

for _ in range(N-1):

    u,v,w = LI()

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

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



def set_color(u,c):

    color[u] = c

    for v,w in edge[u]:

        if color[v] >= 0 : continue

        set_color(v,(w % 2) ^ c)

set_color(1,0)

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

import sys,queue,math,copy,itertools,bisect,collections

sys.setrecursionlimit(10**7)

LI = lambda : [int(x) for x in sys.stdin.readline().split()]

NI = lambda : int(sys.stdin.readline())



N = NI()

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

color = [-1] * (N+1)

for _ in range(N-1):

    u,v,w = LI()

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

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



def set_color(u,c):

    color[u] = c

    for v,w in edge[u]:

        if color[v] >= 0 : continue

        set_color(v,(w % 2) ^ c)

set_color(1,0)

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

import sys, queue, math, copy, itertools, bisect, collections

sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda: [int(x) for x in sys.stdin.readline().split()]
_LI = lambda: [int(x) - 1 for x in sys.stdin.readline().split()]
NI = lambda: int(sys.stdin.readline())
N = NI()
edge = [[] for _ in range(N + 1)]
color = [-1] * (N + 1)
for _ in range(N - 1):
    u, v, w = LI()
    edge[u].append((v, w))
    edge[v].append((u, w))


def set_color(u, c):
    color[u] = c
    for v, w in edge[u]:
        if color[v] >= 0:
            continue
        set_color(v, (w % 2) ^ c)


set_color(1, 0)
print(*color[1:], sep="\n")

import sys, queue, math, copy, itertools, bisect, collections

sys.setrecursionlimit(10**7)
LI = lambda: [int(x) for x in sys.stdin.readline().split()]
NI = lambda: int(sys.stdin.readline())
N = NI()
edge = [[] for _ in range(N + 1)]
color = [-1] * (N + 1)
for _ in range(N - 1):
    u, v, w = LI()
    edge[u].append((v, w))
    edge[v].append((u, w))


def set_color(u, c):
    color[u] = c
    for v, w in edge[u]:
        if color[v] >= 0:
            continue
        set_color(v, (w % 2) ^ c)


set_color(1, 0)
print(*color[1:], sep="\n")

-INF = 10**18 -MOD = 10**9 + 7 -_LI = lambda: [int(x) - 1 for x in sys.stdin.readline().split()]