n = int(eval(input()))



connect_list = [ [] for i in range(n) ]

distance_list = [ -1 for i in range(n) ]

color_list = [ "Gray" for i in range(n) ]

distance_list[0] = 0



for i in range(n-1):

	u, v, w = [ int(v) for v in input().split() ]

	w %= 2

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

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

	



search_list = [0]





while search_list != []:

	s = search_list[0]

	for i in connect_list[s]:

		if distance_list[i[0]] == -1:

			distance_list[i[0]] = (distance_list[s] + i[1]) % 2

			search_list.append(i[0])

	del search_list[0]



for i in distance_list:

	print(i)


import sys

input = sys.stdin.readline



n = int(eval(input()))



connect_list = [ [] for i in range(n) ]

distance_list = [ -1 for i in range(n) ]

color_list = [ "Gray" for i in range(n) ]

distance_list[0] = 0



for i in range(n-1):

	u, v, w = [ int(v) for v in input().split() ]

	w %= 2

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

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

	



search_list = [0]





while search_list != []:

	s = search_list[0]

	for i in connect_list[s]:

		if distance_list[i[0]] == -1:

			distance_list[i[0]] = (distance_list[s] + i[1]) % 2

			search_list.append(i[0])

	del search_list[0]



for i in distance_list:

	print(i)
n = int(eval(input()))
connect_list = [[] for i in range(n)]
distance_list = [-1 for i in range(n)]
color_list = ["Gray" for i in range(n)]
distance_list[0] = 0
for i in range(n - 1):
    u, v, w = [int(v) for v in input().split()]
    w %= 2
    connect_list[u - 1].append((v - 1, w))
    connect_list[v - 1].append((u - 1, w))
search_list = [0]
while search_list != []:
    s = search_list[0]
    for i in connect_list[s]:
        if distance_list[i[0]] == -1:
            distance_list[i[0]] = (distance_list[s] + i[1]) % 2
            search_list.append(i[0])
    del search_list[0]
for i in distance_list:
    print(i)

import sys

input = sys.stdin.readline
n = int(eval(input()))
connect_list = [[] for i in range(n)]
distance_list = [-1 for i in range(n)]
color_list = ["Gray" for i in range(n)]
distance_list[0] = 0
for i in range(n - 1):
    u, v, w = [int(v) for v in input().split()]
    w %= 2
    connect_list[u - 1].append((v - 1, w))
    connect_list[v - 1].append((u - 1, w))
search_list = [0]
while search_list != []:
    s = search_list[0]
    for i in connect_list[s]:
        if distance_list[i[0]] == -1:
            distance_list[i[0]] = (distance_list[s] + i[1]) % 2
            search_list.append(i[0])
    del search_list[0]
for i in distance_list:
    print(i)

+import sys + +input = sys.stdin.readline