import sys

sys.setrecursionlimit(100100)



N=int(eval(input()))

G=[[] for i in range(N)]

for i in range(N-1):

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

    u,v=u-1,v-1

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

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

res=[-1]*N

def dfs(v,p,c):

    res[v]=c

    for nv,w in G[v]:

        if res[nv]>=0:

            continue

        dfs(nv,v,(c+w)%2)

        """

        if w&1:

            dfs(nv,v,1-c)

        else:

            dfs(nv,v,c)

        """

dfs(0,-1,0)

for i in res:

    print(i)

from collections import deque

N=int(input())

G=[[] for i in range(N)]

for i in range(N-1):

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

    u,v=u-1,v-1

    w%=2

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

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

color=[-1]*N

color[0]=0

stack=deque(G[0])

while(stack):

    u,v,w=stack.pop()

    if color[v]!=-1:

        continue

    if w==1:

        color[v]=1-color[u]

    else:

        color[v]=color[u]

    stack.extend(G[v])

[print(i) for i in color]

import sys

sys.setrecursionlimit(100100)
N = int(eval(input()))
G = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = list(map(int, input().split()))
    u, v = u - 1, v - 1
    G[u].append((v, w))
    G[v].append((u, w))
res = [-1] * N


def dfs(v, p, c):
    res[v] = c
    for nv, w in G[v]:
        if res[nv] >= 0:
            continue
        dfs(nv, v, (c + w) % 2)
        """
        if w&1:
            dfs(nv,v,1-c)
        else:
            dfs(nv,v,c)
        """


dfs(0, -1, 0)
for i in res:
    print(i)

from collections import deque

N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    u, v = u - 1, v - 1
    w %= 2
    G[u].append([u, v, w])
    G[v].append([v, u, w])
color = [-1] * N
color[0] = 0
stack = deque(G[0])
while stack:
    u, v, w = stack.pop()
    if color[v] != -1:
        continue
    if w == 1:
        color[v] = 1 - color[u]
    else:
        color[v] = color[u]
    stack.extend(G[v])
[print(i) for i in color]

-import sys +from collections import deque -sys.setrecursionlimit(100100) -N = int(eval(input())) +N = int(input()) -    u, v, w = list(map(int, input().split())) +    u, v, w = map(int, input().split()) -    G[u].append((v, w)) -    G[v].append((u, w)) -res = [-1] * N - - -def dfs(v, p, c): -    res[v] = c -    for nv, w in G[v]: -        if res[nv] >= 0: -            continue -        dfs(nv, v, (c + w) % 2) -        """ -        if w&1: -            dfs(nv,v,1-c) -        else: -            dfs(nv,v,c) -        """ - - -dfs(0, -1, 0) -for i in res: -    print(i) +    w %= 2 +    G[u].append([u, v, w]) +    G[v].append([v, u, w]) +color = [-1] * N +color[0] = 0 +stack = deque(G[0]) +while stack: +    u, v, w = stack.pop() +    if color[v] != -1: +        continue +    if w == 1: +        color[v] = 1 - color[u] +    else: +        color[v] = color[u] +    stack.extend(G[v]) +[print(i) for i in color]