#126_D

import sys

sys.setrecursionlimit(500000)



n=int(input())

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

for _ in range(n-1):

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

    edges[u-1].append((v-1,w))

    edges[v-1].append((u-1,w))

visit=[False for _ in range(n)]

d=[0 for i in range(n)]



def dfs(i):

    visit[i]=True

    if all(visit[i] for i in range(n)):

        print(*d,sep='\n')

        exit()

    for v,w in edges[i]:

        if visit[v]==False:

            d[v]=(d[i]+w)%2

            dfs(v)

            

dfs(0)

#126_D

import sys

sys.setrecursionlimit(500000)



n=int(input())

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

for _ in range(n-1):

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

    edges[u-1].append((v-1,w))

    edges[v-1].append((u-1,w))

visit=[False for _ in range(n)]

d=[0 for i in range(n)]



def dfs(i):

    visit[i]=True

    for v,w in edges[i]:

        if visit[v]==False:

            d[v]=(d[i]+w)%2

            dfs(v)

            

dfs(0)

print(*d,sep='\n')

# 126_D
import sys

sys.setrecursionlimit(500000)
n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    edges[u - 1].append((v - 1, w))
    edges[v - 1].append((u - 1, w))
visit = [False for _ in range(n)]
d = [0 for i in range(n)]


def dfs(i):
    visit[i] = True
    if all(visit[i] for i in range(n)):
        print(*d, sep="\n")
        exit()
    for v, w in edges[i]:
        if visit[v] == False:
            d[v] = (d[i] + w) % 2
            dfs(v)


dfs(0)

# 126_D
import sys

sys.setrecursionlimit(500000)
n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    edges[u - 1].append((v - 1, w))
    edges[v - 1].append((u - 1, w))
visit = [False for _ in range(n)]
d = [0 for i in range(n)]


def dfs(i):
    visit[i] = True
    for v, w in edges[i]:
        if visit[v] == False:
            d[v] = (d[i] + w) % 2
            dfs(v)


dfs(0)
print(*d, sep="\n")

-    if all(visit[i] for i in range(n)): -        print(*d, sep="\n") -        exit() +print(*d, sep="\n")