AtCoder Beginner Contest 126 - Even Relation

We have a tree with N vertices numbered 1 to N.
The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.
Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:
 - For any two vertices painted in the same color, the distance between them is an even number.
Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 10^5
 - 1 \leq u_i < v_i \leq N
 - 1 \leq w_i \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1}

-----Output-----
Print a coloring of the vertices that satisfies the condition, in N lines.
The i-th line should contain 0 if Vertex i is painted white and 1 if it is painted black.
If there are multiple colorings that satisfy the condition, any of them will be accepted.

-----Sample Input-----
3
1 2 2
2 3 1

-----Sample Output-----
0
0
1

Difficulty: MEDIUM

Starter code:

Solutions:
n = int(input())
col = [-1] * n
e = [[[], []] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	w %= 2
	e[u][w].append(v)
	e[v][w].append(u)
col[0] = 1
from collections import deque
dq = deque([])
dq.append(0)
while dq:
	a = dq.pop()
	b = col[a]
	for i in range(2):
		for ne in e[a][i]:
			if col[ne] == -1:
				col[ne] = b ^ i
				dq.appendleft(ne)
print(*col, sep='\n')


(n, *t) = map(int, open(0).read().split())
e = [[] for _ in [0] * n]
for (v, w, c) in zip(t[::3], t[1::3], t[2::3]):
	e[v - 1] += ((w - 1, c),)
	e[w - 1] += ((v - 1, c),)
q = [0]
f = [0] + [-1] * ~-n
while q:
	v = q.pop()
	for (w, c) in e[v]:
		if -1 < f[w]:
			continue
		f[w] = (c + f[v]) % 2
		q += (w,)
print(*f)


import sys
from sys import stdin
input = stdin.readline
sys.setrecursionlimit(20000000)

def main():
	N = int(input())
	G = [[] for _ in range(N + 1)]
	for i in range(N - 1):
		(u, v, w) = map(int, input().split())
		G[u].append((v, w))
		G[v].append((u, w))
	color = [-1] * (N + 1)
	color[1] = 0

	def dfs(now):
		for (next_, w) in G[now]:
			if color[next_] == -1:
				color[next_] = w % 2 ^ color[now]
				dfs(next_)
	dfs(1)
	for i in range(1, N + 1):
		print(color[i])
main()


N = int(input())
uvw = [[int(x) for x in input().split()] for _ in range(N - 1)]
path = [[] for _ in range(N)]
ans = [-1] * N
ans[0] = 0
for (u, v, w) in uvw:
	path[u - 1].append([v - 1, w % 2])
	path[v - 1].append([u - 1, w % 2])
Q = [0]
while Q:
	v = Q.pop(-1)
	for (p, d) in path[v]:
		if ans[p] == -1:
			ans[p] = (ans[v] + d) % 2
			Q.append(p)
for a in ans:
	print(a)


from collections import *
(n, *t) = map(int, open(0).read().split())
e = [[] for _ in range(n)]
for (v, w, c) in zip(t[::3], t[1::3], t[2::3]):
	e[v - 1].append((w - 1, c))
	e[w - 1].append((v - 1, c))
q = deque([(0, 0)])
f = [0] + [-1] * ~-n
while q:
	(v, c) = q.pop()
	for (w, d) in e[v]:
		if -1 < f[w]:
			continue
		d = (c + d) % 2
		f[w] = d
		q.append((w, d))
print(*f, sep='\n')


N = int(input())
links = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	links[u - 1].append((v - 1, w))
	links[v - 1].append((u - 1, w))
distance = [-1] * N
distance[0] = 0
q = [0]
while q:
	p = q.pop()
	for (n, w) in links[p]:
		if distance[n] == -1:
			distance[n] = distance[p] + w
			q.append(n)
for i in distance:
	print(i % 2)


n = int(input())
L = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	L[u].append([v, w])
	L[v].append([u, w])
ans = [-1] * n
ans[0] = 0
from collections import deque
que = deque([])
que.append(0)
while que:
	v = que.popleft()
	for (u, w) in L[v]:
		if ans[u] != -1:
			continue
		ans[u] = (ans[v] + w) % 2
		que.append(u)
for a in ans:
	print(a)


from sys import setrecursionlimit
setrecursionlimit(10 ** 8)
N = int(input())
Graph = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	w %= 2
	Graph[u - 1].append((v - 1, w))
	Graph[v - 1].append((u - 1, w))
root = 0
color = [-1] * N
color[0] = 0

def dfs(x):
	for (i, w) in Graph[x]:
		if color[i] == -1:
			color[i] = (color[x] + w) % 2
			dfs(i)
dfs(0)
for i in range(N):
	print(color[i])


N = int(input())
edge = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	edge[u - 1] += [[u - 1, v - 1, w % 2]]
	edge[v - 1] += [[v - 1, u - 1, w % 2]]
group = [0] + [-1] * (N - 1)
cnt = N - 1
path = edge[0]
while path:
	uv = path.pop()
	if group[uv[1]] == -1:
		group[uv[1]] = (group[uv[0]] + uv[2]) % 2
		for e in edge[uv[1]]:
			path.append(e)
for i in range(N):
	print(group[i])


import sys
from collections import deque
readline = sys.stdin.readline
n = int(readline())
G = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, readline().split())
	G[u - 1].append((v - 1, w))
	G[v - 1].append((u - 1, w))
V = [-1] * n
V[0] = 0
que = deque([0])
while que:
	nw = que.popleft()
	for (nx, d) in G[nw]:
		if V[nx] != -1:
			continue
		V[nx] = (V[nw] + d) % 2
		que.append(nx)
for v in V:
	print(v)


import sys
sys.setrecursionlimit(10 ** 9)
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	w %= 2
	(u, v) = (u - 1, v - 1)
	edge[u].append((v, w))
	edge[v].append((u, w))
ret = [0] * N

def dfs(pv, v, dist):
	ret[v] = dist
	for (nv, w) in edge[v]:
		if nv == pv:
			continue
		dfs(v, nv, (dist + w) % 2)
dfs(-1, 0, 0)
print(*ret, sep='\n')


from collections import deque
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = list(map(int, input().split()))
	(u, v) = (u - 1, v - 1)
	graph[u].append([v, w])
	graph[v].append([u, w])
colors = [-1 for _ in range(N)]
stack = deque()
stack.append(0)
colors[0] = 0
while stack:
	n = stack.popleft()
	for (_next, w) in graph[n]:
		if colors[_next] != -1:
			continue
		colors[_next] = (colors[n] + w) % 2
		stack.append(_next)
for c in colors:
	print(c)


import sys
sys.setrecursionlimit(10 ** 6)

def dfs(v):
	check[v] = True
	for (u, w) in T[v]:
		if check[u]:
			continue
		dist[u] = dist[v] + w
		dfs(u)
N = int(input())
T = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	T[u].append((v, w))
	T[v].append((u, w))
dist = [0] * (N + 1)
check = [False] * (N + 1)
dfs(1)
print(*[d % 2 for d in dist[1:]], sep='\n')


import sys
sys.setrecursionlimit(10 ** 8)
N = int(input())
UVW = [tuple(map(int, input().split())) for i in range(N - 1)]
es = [[] for _ in range(N)]
for (u, v, w) in UVW:
	(u, v) = (u - 1, v - 1)
	es[u].append((v, w))
	es[v].append((u, w))
ans = [None] * N
ans[0] = 0

def dfs(v, p=-1):
	for (to, d) in es[v]:
		if to == p:
			continue
		ans[to] = ans[v] ^ d % 2
		dfs(to, v)
dfs(0)
print(*ans, sep='\n')


from math import ceil, floor, factorial, gcd, sqrt, log2, cos, sin, tan, acos, asin, atan, degrees, radians, pi, inf, comb
from itertools import accumulate, groupby, permutations, combinations, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(MAP())

def bfs():
	dist = [-1] * n
	que = deque([0])
	dist[0] = 0
	while que:
		v = que.popleft()
		d = dist[v]
		for w in g[v]:
			if dist[w[0]] > -1:
				continue
			dist[w[0]] = d + w[1]
			que.append(w[0])
	return dist
n = INT()
g = [[] for i in range(n)]
for i in range(n - 1):
	(x, y, z) = MAP()
	g[x - 1].append([y - 1, z])
	g[y - 1].append([x - 1, z])
for k in bfs():
	print(0 if k % 2 == 0 else 1)


import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
T = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	w %= 2
	T[u].append((v, w))
	T[v].append((u, w))
ans = [0] * n

def dfs(u, p=-1, c=0):
	for (v, w) in T[u]:
		if v == p:
			continue
		nc = (c + 1) % 2 if w else c
		ans[v] = nc
		dfs(v, u, nc)
dfs(0)
print('\n'.join(map(str, ans)))


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
a = [[] for _ in range(N)]
ans = [0] * N
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	a[u - 1].append([v - 1, w])
	a[v - 1].append([u - 1, w])

def calc(u, b):
	for (v, w) in a[u]:
		if not b == v:
			ans[v] = (ans[u] + w) % 2
			calc(v, u)
calc(0, -1)
for i in ans:
	if i % 2 == 0:
		print(0)
	else:
		print(1)


n = int(input())
a = [-1 for i in range(n)]
d = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	d[u].append([v, w])
	d[v].append([u, w])
e = 0
a[0] = 0
l = []
for (i, j) in d[0]:
	a[i] = (a[0] + j) % 2
	l.append(i)
while len(l) > 0:
	b = l.pop()
	for (i, j) in d[b]:
		if a[i] == -1:
			a[i] = (a[b] + j) % 2
			l.append(i)
print(*a, sep='\n')


import sys
sys.setrecursionlimit(10 ** 7)

def dfs(v):
	for (u, w) in e[v]:
		if c[u] != -1:
			continue
		c[u] = (c[v] + w) % 2
		dfs(u)
n = int(input())
e = tuple((set() for _ in range(n)))
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	e[u].add((v, w))
	e[v].add((u, w))
c = [-1] * n
c[0] = 0
dfs(0)
print(*c, sep='\n')


from collections import deque
n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	g[u - 1].append((v - 1, w))
	g[v - 1].append((u - 1, w))
ds = [-1] * n
dq = deque([0])
ds[0] = 0
while dq:
	t = dq.popleft()
	for i in g[t]:
		if ds[i[0]] == -1:
			ds[i[0]] = ds[t] + i[1]
			dq.append(i[0])
for i in ds:
	if i % 2 == 0:
		print(0)
	else:
		print(1)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 9)
n = int(input())
edges = [[] for i in range(n)]
for i in range(n - 1):
	(a, s, w) = map(int, input().split())
	edges[a - 1].append([s - 1, w])
	edges[s - 1].append([a - 1, w])
colors = [-1] * n
colors[0] = 1

def dfs(now):
	for (to, cost) in edges[now]:
		if colors[to] == -1:
			colors[to] = (cost + colors[now]) % 2
			dfs(to)
dfs(0)
print(*colors, sep='\n')


from sys import setrecursionlimit
setrecursionlimit(10 ** 7)
n = int(input())
uvw = [list(map(int, input().split())) for i in range(n - 1)]
d = [-1 for i in range(n)]
edge = [[] for i in range(n)]
for (u, v, w) in uvw:
	edge[u - 1].append((v - 1, w))
	edge[v - 1].append((u - 1, w))

def dfs(now, D):
	d[now] = D
	for (i, j) in edge[now]:
		if d[i] == -1:
			dfs(i, D + j)
dfs(0, 0)
for i in d:
	print(i % 2)


import sys
sys.setrecursionlimit(10 ** 7)

class TreeNode:

	def __init__(self, num):
		self.num = num
		self.vertexs = []
		self.color = None

	def set_color(self, color):
		self.color = color

class Tree:

	def __init__(self, N):
		self.nodes = [TreeNode(i) for i in range(N)]

	def set_vertex(self, u, v, w):
		self.nodes[u - 1].vertexs.append((v - 1, w))
		self.nodes[v - 1].vertexs.append((u - 1, w))

	def set_color(self):
		self.nodes[0].set_color(0)

		def set_color(node, prev_node):
			for (n, w) in node.vertexs:
				if n != prev_node.num:
					continue
				if w % 2 == 0:
					node.set_color(prev_node.color)
				else:
					new_color = abs(prev_node.color - 1)
					node.set_color(new_color)
		self.do_and_next(0, -1, set_color)

	def print_tree_num(self):
		for (i, node) in enumerate(self.nodes):
			print(i, node.vertexs, node.color)

	def print_tree_deep(self):
		print_color = lambda x, p: print(x.color)
		self.do_and_next(0, -1, print_color)

	def do_and_next(self, node_num, prev_node_num, f):
		f(self.nodes[node_num], self.nodes[prev_node_num])
		for (n, w) in self.nodes[node_num].vertexs:
			if n == prev_node_num:
				continue
			self.do_and_next(n, node_num, f)

	def print_color(self):
		for node in self.nodes:
			print(node.color)
N = int(input())
tree = Tree(N)
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	tree.set_vertex(u, v, w)
tree.set_color()
tree.print_color()


import sys
sys.setrecursionlimit(pow(10, 7))

def dfs(v, c):
	color[v] = c
	for x in glaph[v]:
		(u, w) = (x[0], x[1])
		if color[u] != -1:
			continue
		if w % 2 == 0:
			dfs(u, c)
		else:
			dfs(u, 1 - c)
n = int(input())
color = [-1] * n
glaph = [[] * n for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	glaph[u - 1].append((v - 1, w))
	glaph[v - 1].append((u - 1, w))
dfs(v=0, c=0)
for i in color:
	print(i)


import sys
sys.setrecursionlimit(9 ** 9)
n = int(input())
C = [0 for _ in range(n)]
L = [[] for _ in range(n)]
for j in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	L[u].append([v, w])
	L[v].append([u, w])

def a(n, v, d):
	for i in L[n]:
		if d % 2 == 1:
			C[n] = 1
		if v != i[0]:
			a(i[0], n, d + i[1])
a(0, 0, 0)
for c in C:
	print(c)


N = int(input())
e_list = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	w %= 2
	e_list[u - 1].append([v - 1, w])
	e_list[v - 1].append([u - 1, w])
stack = [0]
ans = [-1] * N
ans[0] = 0
while stack:
	x = stack.pop()
	for (v, w) in e_list[x]:
		if ans[v] != -1:
			continue
		else:
			ans[v] = ans[x] ^ w
			stack.append(v)
print(*ans, sep='\n')


import sys
sys.setrecursionlimit(1000000)
n = int(input())
graph = [[] for i in range(n)]
color = [-1] * n
for i in range(n - 1):
	(a, b, c) = map(int, input().split())
	graph[a - 1].append([b - 1, c % 2])
	graph[b - 1].append([a - 1, c % 2])

def coloring(pre, c):
	color[pre] = c
	for (i, j) in graph[pre]:
		if color[i] < 0:
			coloring(i, color[pre] ^ j)
coloring(0, 1)
for i in color:
	print(i)


import sys
sys.setrecursionlimit(pow(10, 9))
N = int(input())
G = [[] for _ in range(N)]

def dfs(v, dist):
	for (nv, e_dist) in G[v]:
		if ans[nv] == -1:
			ans[nv] = (dist + e_dist) % 2
			dfs(nv, dist + e_dist)
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	G[u - 1].append([v - 1, w])
	G[v - 1].append([u - 1, w])
ans = [-1] * N
dfs(0, 0)
print(*ans, sep='\n')


N = int(input())
d = dict(zip([i for i in range(1, N + 1)], [[] for _ in range(N)]))
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	d[u].append([v, w])
	d[v].append([u, w])
colors = [0 for i in range(N)]
l = [[1, 1]]
while l:
	(node, parent) = l.pop()
	edges = d[node]
	for (v, w) in edges:
		if v == parent:
			continue
		colors[v - 1] = (colors[node - 1] + w) % 2
		l.append([v, node])
for c in colors:
	print(c)


import sys
import copy
sys.setrecursionlimit(10 ** 9)

def dfs(seen, graph, i):
	for (v, w) in graph[i]:
		if seen[v - 1] != -1:
			continue
		seen[v - 1] = abs(w % 2 - seen[i])
		dfs(seen, graph, v - 1)

def main():
	n = int(input())
	graph = [[] for _ in range(n)]
	for _ in range(n - 1):
		(ui, vi, wi) = map(int, input().split())
		graph[ui - 1].append((vi, wi))
		graph[vi - 1].append((ui, wi))
	seen = [-1 for _ in range(n)]
	seen[0] = 0
	for i in range(n - 1):
		dfs(seen, graph, i)
	print(*seen, sep='\n')
main()


import sys
sys.setrecursionlimit(10 ** 9)

def dfs(now):
	for (to, dis) in G[now]:
		if color[to] == -1:
			color[to] = (color[now] + dis) % 2
			dfs(to)
N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 0
for i in range(N - 1):
	(a, b, c) = map(int, input().split())
	a -= 1
	b -= 1
	G[a].append([b, c % 2])
	G[b].append([a, c % 2])
dfs(0)
print(*color, sep='\n')


n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	g[u - 1].append((v - 1, w))
	g[v - 1].append((u - 1, w))
l = [-1] * n
s = [(1, 0)]
while s:
	(b, c) = s.pop()
	l[b] = c % 2
	for (x, y) in g[b]:
		if l[x] == -1:
			s.append((x, y + c))
for i in l:
	print(i)


N = int(input())
adj = [[] for _ in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	(u, v) = (u - 1, v - 1)
	w %= 2
	adj[u].append((v, w))
	adj[v].append((u, w))
color = [None] * N
color[0] = False
stack = [0]
while stack:
	u = stack.pop()
	for (v, w) in adj[u]:
		if color[v] is None:
			color[v] = w % 2 ^ color[u]
			stack += [v]
for c in color:
	print(1 if c else 0)


import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
G = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	G[u].append((v, w))
	G[v].append((u, w))
D = [-1 for _ in range(n + 1)]
D[1] = 0
L = deque()
L.append(1)
while L:
	p = L.popleft()
	for i in G[p]:
		if D[i[0]] == -1:
			D[i[0]] = D[p] + i[1]
			L.append(i[0])
for m in range(1, n + 1):
	print(D[m] % 2)


import sys
sys.setrecursionlimit(10 ** 9)

def dfs(i):
	if reached[i] == 1:
		return
	reached[i] = 1
	for dic in uv[i]:
		to = dic['to']
		w = dic['weight']
		if w % 2 == 0:
			color[to] = color[i]
		else:
			color[to] = int(not color[i])
		dfs(to)
n = int(input())
color = [0] * (n + 1)
reached = [0] * (n + 1)
uv = [[] * (n + 1) for i in range(n + 1)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	uv[u].append({'to': v, 'weight': w})
	uv[v].append({'to': u, 'weight': w})
dfs(1)
for i in color[1:]:
	print(i)


class Graph:

	def __init__(self):
		self.adjacency_dict = {}
		self.weight = []

	def add_vertex(self, v):
		self.adjacency_dict[v] = []
		self.weight.append([])

	def add_edge(self, v1, v2, w):
		self.adjacency_dict[v1].append(v2)
		self.adjacency_dict[v2].append(v1)
		self.weight[v1].append(w)
		self.weight[v2].append(w)

	def get_vertexes(self):
		return list(self.adjacency_dict.keys())

	def get_edges(self, v):
		return (self.adjacency_dict[v], self.weight[v])

	def print_graph(self):
		print(self.adjacency_dict)
n = int(input())
res = []
g = Graph()
for i in range(n):
	res.append(-1)
	g.add_vertex(i)
for i in range(n - 1):
	(u, v, w) = list(map(int, input().strip().split()))
	g.add_edge(u - 1, v - 1, w % 2)
q = []
res[0] = 0
q.append(0)
while len(q) > 0:
	v = q.pop()
	(u_l, w_l) = g.get_edges(v)
	for (u, w) in zip(u_l, w_l):
		if res[u] != -1:
			continue
		res[u] = (res[v] + w) % 2
		q.append(u)
for i in range(n):
	print(res[i])


n = int(input())
gr = [dict() for _ in range(n)]
l = [10 * 6] * n
l[0] = 0
for _ in range(n - 1):
	(x, y, w) = map(int, input().split())
	w %= 2
	gr[x - 1][y - 1] = w
	gr[y - 1][x - 1] = w
seen = set()
q = [0]
while q:
	cur = q.pop()
	seen.add(cur)
	for x in set(gr[cur].keys()) - seen:
		l[x] = l[cur] + gr[cur][x]
		q.append(x)
for i in range(n):
	print(l[i] % 2)


import sys
sys.setrecursionlimit(1000000)

def input():
	return sys.stdin.readline()
n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b, c) = [int(i) - 1 for i in input().split()]
	c += 1
	e[a].append([b, c])
	e[b].append([a, c])
c = [0] * n

def dfs(i=0, r=-1, co=0):
	c[i] = co
	for (j, k) in e[i]:
		if j != r:
			dfs(j, i, (co + k) % 2)
dfs()
print('\n'.join(map(str, c)))


N = int(input())
E = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	E[u].append((v, w))
	E[v].append((u, w))
color = [-1 for _ in range(N)]
stack = [u]
color[u] = 0
while stack:
	u = stack.pop()
	for (v, w) in E[u]:
		if color[v] == -1:
			stack.append(v)
		if w % 2 == 0:
			color[v] = color[u]
		else:
			color[v] = (color[u] + 1) % 2
for i in range(N):
	print(color[i])


def solve():
	from collections import deque
	(n, *l) = map(int, open(0).read().split())
	con = [[] for _ in range(n)]
	dist = [None] * n
	dist[0] = 0
	for (a, b, c) in zip(*[iter(l)] * 3):
		con[a - 1] += [(b - 1, c % 2)]
		con[b - 1] += [(a - 1, c % 2)]
	stk = deque([0])
	while stk:
		cur = stk.pop()
		for (nxt, d) in con[cur]:
			if dist[nxt] == None:
				stk.append(nxt)
				dist[nxt] = (dist[cur] + d) % 2
	print(*dist, sep='\n')
solve()


N = int(input())
tree = [[] for _ in range(N + 1)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	tree[u].append([v, w])
	tree[v].append([u, w])
d = [-1 for _ in range(N + 1)]
d[1] = 0
q = [1]
while q:
	cur = q.pop()
	for (n, l) in tree[cur]:
		if d[n] == -1:
			d[n] = d[cur] + l
			q.append(n)
for l in d[1:]:
	print(l % 2)


n = int(input())
c = [[] for i in range(n + 1)]
d = {}
for i in range(n - 1):
	(x, y, z) = map(int, input().split())
	c[x].append(y)
	c[y].append(x)
	d[x, y] = z
d[1, 1] = 0
stack = [1]
parent = [None] * (n + 1)
while stack:
	i = stack.pop()
	for j in c[i]:
		if j == parent[i]:
			continue
		parent[j] = i
		d[1, j] = d[1, i] + d[tuple(sorted([i, j]))]
		stack.append(j)
for i in range(1, n + 1):
	print(d[1, i] % 2)


n = int(input())
G = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	G[u - 1].append([v - 1, w])
	G[v - 1].append([u - 1, w])
dist = [-1] * n
from collections import deque
q = deque()
q.append(0)
dist[0] = 0
while q:
	cur = q.popleft()
	for (nx, nd) in G[cur]:
		if dist[nx] != -1:
			continue
		dist[nx] = (dist[cur] + nd) % 2
		q.append(nx)
print(*dist, sep='\n')


import sys
from collections import deque
input = sys.stdin.readline

def main():
	N = int(input())
	G = [[] for _ in range(N)]
	for i in range(N - 1):
		(u, v, w) = list(map(int, input().split()))
		u -= 1
		v -= 1
		G[u].append((v, w))
		G[v].append((u, w))
	ans = [-1] * N
	ans[0] = 0
	stack = deque([(-1, 0)])
	while stack:
		(p, u) = stack.pop()
		for (v, w) in G[u]:
			if v == p:
				continue
			if w % 2 == 0:
				ans[v] = ans[u]
			else:
				ans[v] = (ans[u] + 1) % 2
			stack.append((u, v))
	print('\n'.join(map(str, ans)))

def __starting_point():
	main()
__starting_point()


from collections import deque
n = int(input())
g = tuple((set() for _ in range(n)))
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	g[u].add((v, w))
	g[v].add((u, w))
d = [-1] * n
d[0] = 0
q = deque()
q.append(0)
while q:
	v = q.popleft()
	for (u, w) in g[v]:
		if d[u] != -1:
			continue
		d[u] = (d[v] + w) % 2
		q.append(u)
print(*d, sep='\n')


from collections import deque
n = int(input())
g = [list() for _ in range(n)]
visited = [True] * n
coler = [0] * n
for _ in range(1, n):
	(v1, v2, w) = map(int, input().split())
	v1 -= 1
	v2 -= 1
	w %= 2
	g[v1].append((v2, w))
	g[v2].append((v1, w))
q = deque([0])
visited[0] = False
while q:
	a = q.pop()
	for (v, w) in g[a]:
		if visited[v]:
			visited[v] = False
			coler[v] = (coler[a] + w) % 2
			q.append(v)
print(*coler, sep='\n')


N = int(input())
link = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	link[u].append((v, w))
	link[v].append((u, w))
dist = [-1] * (N + 1)
dist[1] = 0
q = [1]
while q:
	p = q.pop()
	for (n, w) in link[p]:
		if dist[n] == -1:
			dist[n] = dist[p] + w
			q.append(n)
for i in range(1, N + 1):
	if dist[i] % 2 == 0:
		print(0)
	else:
		print(1)


from collections import deque
n = int(input())
arr = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	arr[u - 1].append([v - 1, w])
	arr[v - 1].append([u - 1, w])
que = deque([0])
ans = [0] * n
visited = [0] * n
while que:
	x = que.popleft()
	visited[x] = -1
	dis = ans[x]
	for tup in arr[x]:
		if visited[tup[0]] > -1:
			ans[tup[0]] = (dis + tup[1]) % 2
			que.append(tup[0])
print(*ans, sep='\n')


n = int(input())
d = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	d[u - 1].append([v - 1, w])
	d[v - 1].append([u - 1, w])
ans = [[] for i in range(n)]
ans[0].append(0)
q = [0]
while q:
	x = q.pop()
	for (u, w) in d[x]:
		if not ans[u]:
			buf = ans[x][0]
			if w % 2 == 1:
				buf = (buf + 1) % 2
			ans[u].append(buf)
			q.append(u)
for i in ans:
	print(*i)


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
links = [[] for _ in range(N)]
result = [0 for _ in range(N)]
memo = [0 for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	links[u].append([v, w])
	links[v].append([u, w])

def color(u):
	if memo[u]:
		return
	for l in links[u]:
		result[l[0]] = abs(l[1] % 2 - result[u])
	memo[u] = 1
	for l in links[u]:
		color(l[0])
color(0)
for r in result:
	print(r)


import sys
input = sys.stdin.readline
N = int(input())
A = [[] for _ in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	A[u - 1].append((v - 1, w))
	A[v - 1].append((u - 1, w))
color = [-1] * N
color[0] = 0
stack = [0]
while stack:
	u = stack.pop()
	for (v, w) in A[u]:
		if color[v] != -1:
			continue
		color[v] = color[u] ^ w & 1
		stack.append(v)
for c in color:
	print(c)


from collections import deque
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	edge[u - 1].append([v - 1, w])
	edge[v - 1].append([u - 1, w])
color = [-1] * n
que = deque([[0, -1, 0]])
while que:
	(u, v, c) = que.popleft()
	color[u] = c
	for (i, j) in edge[u]:
		if i == v:
			continue
		que.append([i, u, (c + j) % 2])
print(*color, sep='\n')


import sys
sys.setrecursionlimit(100000)
N = int(input())
d = {}
e = [[] for _ in range(N)]
dd = [-1] * N
for _ in range(N - 1):
	(u, v, w) = list(map(int, input().split()))
	e[u - 1].append(v - 1)
	e[v - 1].append(u - 1)
	d[u - 1, v - 1] = d[v - 1, u - 1] = w

def dfs(i, _d):
	dd[i] = _d
	for c in e[i]:
		if dd[c] != -1:
			continue
		dfs(c, _d + d[i, c])
dfs(0, 0)
for _dd in dd:
	print(_dd % 2)


from collections import deque

def bfs(cur):
	q = deque()
	q.append(cur)
	while q:
		cur = q.popleft()
		for (nx, e_dist) in G[cur]:
			if ans[nx] != -1:
				continue
			ans[nx] = (ans[cur] + e_dist) % 2
			q.append(nx)
n = int(input())
G = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	G[u - 1].append([v - 1, w])
	G[v - 1].append([u - 1, w])
ans = [-1] * n
bfs(0)
print(*ans, sep='\n')


from collections import deque
N = int(input())
tree = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	tree[u].append((v, w))
	tree[v].append((u, w))
ans = [-1] * (N + 1)
q = deque()
q.append((1, 0, None))
while len(q):
	(u, d, prev) = q.pop()
	ans[u] = d % 2
	for (v, w) in tree[u]:
		if v != prev:
			q.append((v, d + w, u))
for v in ans[1:]:
	print(v)


import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
G = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b, c) = map(int, input().split())
	G[a] += ((b, c),)
	G[b] += ((a, c),)
d = [0] * (n + 1)

def f(v, p, u):
	d[v] = u
	for (t, c) in G[v]:
		if p != t:
			f(t, v, u + c)
f(1, 0, 0)
for i in range(n):
	if d[i + 1] % 2 == 0:
		print(1)
	else:
		print(0)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def dfs(u: int, v: int):
	cv = color[v]
	for (s, k) in graph[v]:
		if s == u:
			continue
		elif color[s] != -1:
			continue
		elif k % 2 == 0:
			color[s] = cv
			dfs(v, s)
		else:
			color[s] = (cv + 1) % 2
			dfs(v, s)

def main():
	nonlocal color, graph
	N = int(input())
	graph = [[] for _ in range(N)]
	for _ in range(N - 1):
		(u, v, w) = list(map(int, input().split()))
		graph[u - 1].append((v - 1, w))
		graph[v - 1].append((u - 1, w))
	color = [-1] * N
	color[0] = 0
	dfs(-1, 0)
	for c in color:
		print(c)

def __starting_point():
	main()
__starting_point()


import _heapq
inf = float('inf')

def prim():
	color = ['white' for _ in range(n + 1)]
	D = [inf for _ in range(n + 1)]
	M = [[] for _ in range(n + 1)]
	for (u, v, w) in UVW:
		M[u].append([w, v])
		M[v].append([w, u])
	queue = [[0, 1]]
	_heapq.heapify(queue)
	color[1] = 'gray'
	D[1] = 1
	while len(queue) > 0:
		num = _heapq.heappop(queue)[1]
		if color[num] == 'black':
			continue
		color[num] = 'black'
		for (i, j) in M[num]:
			if D[j] > i and color[j] != 'black':
				if i % 2 == 0:
					D[j] = D[num]
				else:
					D[j] = -D[num]
				color[j] = 'gray'
				_heapq.heappush(queue, [i, j])
	return D[1:]
n = int(input())
UVW = [list(map(int, input().split())) for _ in range(n - 1)]
for i in prim():
	if i == 1:
		print(i)
	else:
		print(0)


import sys
sys.setrecursionlimit(114514)
N = int(input())
path = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	path[u].append((v, w))
	path[v].append((u, w))
d = [-1] * (N + 1)

def walk(i, c):
	if d[i] == -1:
		d[i] = c
		for (x, w) in path[i]:
			walk(x, c + w)
walk(1, 0)
for c in d[1:]:
	print(c % 2)


import sys
sys.setrecursionlimit(10 ** 8)
N = int(input())
graph = [[] for _ in range(N)]
for i in range(1, N):
	(u, v, w) = list(map(int, input().split()))
	graph[u - 1].append((v - 1, w))
	graph[v - 1].append((u - 1, w))
color = [0 for _ in range(N)]
visited = [False for _ in range(N)]

def dfs(now):
	for adj in graph[now]:
		(v, dist) = adj
		if visited[v]:
			continue
		visited[v] = True
		color[v] = color[now] + dist
		dfs(v)
	return
for start in range(N):
	if not visited[start]:
		color[start] = 0
		visited[start] = True
		dfs(start)
for i in range(N):
	print(color[i] % 2)


import sys
sys.setrecursionlimit(100000000)
n = int(input())
graph = [[] for _ in range(n)]
color = [-1] * n
dist = [-1] * n
dist[0] = 0
visited = [0] * n
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	graph[u] += [[v, w]]
	graph[v] += [[u, w]]

def dfs(u, d):
	for (v, w) in graph[u]:
		if dist[v] == -1:
			dist[v] = (w + d) % 2
			dfs(v, d + w)
dfs(0, 0)
for i in dist:
	print(i)


n = int(input())
explored = set()
next = [[] for _ in range(n)]
from collections import deque
ls = []
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	ls.append((u - 1, v - 1, w % 2))
	next[u - 1].append((v - 1, w % 2))
	next[v - 1].append((u - 1, w % 2))
ans = [-1] * n
exploring = deque()
next_que = deque([0])
ans[0] = 0
explored.add(0)
while next_que:
	i = next_que.popleft()
	exploring.extend(next[i])
	while exploring:
		(a, b) = exploring.popleft()
		ans[a] = (ans[i] + b) % 2
		list = next[a]
		if a not in explored:
			next_que.append(a)
		explored.add(a)
for i in ans:
	print(i)


from collections import deque
N = int(input())
a = [set() for v in range(N)]
for e in range(1, N):
	(u, v, w) = map(int, input().split())
	a[u - 1].add((v - 1, w))
	a[v - 1].add((u - 1, w))
d = [-1 for v in range(N)]
q = deque()
q.append(0)
d[0] = 0
while q:
	u = q.popleft()
	for (v, w) in a[u]:
		if d[v] == -1:
			d[v] = d[u] + w
			q.append(v)
for di in d:
	print(di % 2)


import sys
sys.setrecursionlimit(10 ** 9)
N = int(input())
graph = [[] for _ in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	(u, v) = (u - 1, v - 1)
	graph[u].append([v, w])
	graph[v].append([u, w])
check = [0] * N
ans = [0] * N

def solve(x):
	check[x] = 1
	for (i, d) in graph[x]:
		if check[i] == 0:
			ans[i] = (ans[x] + d) % 2
			solve(i)
solve(0)
for i in range(N):
	print(ans[i])


n = int(input())
k = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b, c) = map(int, input().split())
	k[a - 1].append([b - 1, c])
	k[b - 1].append([a - 1, c])
s = [0] * n
from collections import deque
d = deque()
d.append(0)
v = [False] * n
v[0] = True
while d:
	g = d.popleft()
	for i in k[g]:
		if v[i[0]]:
			continue
		d.append(i[0])
		v[i[0]] = True
		if i[1] % 2 == 0:
			s[i[0]] = s[g]
		else:
			s[i[0]] = [1, 0][s[g]]
for i in s:
	print(i)


n = int(input())
cost = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b, c) = (int(x) for x in input().split())
	cost[a - 1].append([b - 1, c])
	cost[b - 1].append([a - 1, c])
dp = [0] * n
move = [0]
check = [-1] * n
check[0] = 0
while len(move):
	v = move.pop(0)
	for (i, j) in cost[v]:
		if check[i] == -1:
			dp[i] = dp[v] + j
			check[i] = 1
			move.append(i)
for i in dp:
	print(i % 2)


import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
t = {i: {} for i in range(n)}
ans = [-1] * n
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	t[u - 1][v - 1] = w
	t[v - 1][u - 1] = w

def dfs(x):
	for y in t[x]:
		del t[y][x]
		ans[y] = ans[x] if t[x][y] % 2 == 0 else 1 - ans[x]
		if len(t[y]) > 0:
			dfs(y)
ans[0] = 0
dfs(0)
for i in range(n):
	print(ans[i])


N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	T[u - 1].append([v - 1, w])
	T[v - 1].append([u - 1, w])
D = [-1] * N
D[0] = 0
Q = [0]
while Q:
	q = Q.pop()
	for (adj, w) in T[q]:
		if D[adj] < 0:
			D[adj] = D[q] + w
			Q.append(adj)
for d in D:
	print(d % 2)


import collections
N = int(input())
Map = [[] for j in range(N + 1)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	Map[u].append((v, w))
	Map[v].append((u, w))
q = collections.deque()
q.append(1)
ans = [-1 for i in range(N + 1)]
ans[1] = 0
while q:
	v = q.popleft()
	for (e, w) in Map[v]:
		if ans[e] == -1:
			ans[e] = ans[v] + w
			q.append(e)
for i in range(1, N + 1):
	print(ans[i] % 2)


import sys
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, sys.stdin.readline().split())
	u -= 1
	v -= 1
	G[u].append((v, w))
	G[v].append((u, w))
done = {}
todo = [(0, 0, 0)]
while todo:
	(i, c, d) = todo.pop()
	for (ni, dd) in G[i]:
		if ni in done:
			continue
		nd = d + dd
		nc = nd % 2
		todo.append((ni, nc, nd))
	done[i] = c
for i in range(N):
	print(done[i])


n = int(input())
l = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	l[u].append([v, w])
	l[v].append([u, w])
c = [-1] * (n - 1)
color = [0] + c
x = [0]
while x:
	current = x.pop(0)
	for (y, d) in l[current]:
		if color[y] > -1:
			continue
		color[y] = (color[current] + d) % 2
		x.append(y)
for col in color:
	print(col)


from collections import deque
n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	g[u].append([v, w])
	g[v].append([u, w])
used = [0] * n
used[0] = 1
parity = [-1] * n
parity[0] = 0
que = deque()
que.append(0)
while que:
	v = que.popleft()
	for (nv, w) in g[v]:
		if used[nv]:
			continue
		parity[nv] = (parity[v] + w) % 2
		used[nv] = 1
		que.append(nv)
for i in range(n):
	print(parity[i])


n = int(input())
node = [-1 for i in range(n)]
g = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	w %= 2
	g[u].append([v, w])
	g[v].append([u, w])
queue = [0]
node[0] = 0
while len(queue) > 0:
	t = queue.pop()
	for (v, w) in g[t]:
		if node[v] > -1:
			continue
		node[v] = node[t] ^ w
		queue.append(v)
for i in range(n):
	print(node[i])


import queue
n = int(input())
e = [[] for _ in range(n)]
INF = 10 ** 18
d = [INF] * n
for _ in range(n - 1):
	(v, u, w) = map(int, input().split())
	e[v - 1] += [(u - 1, w)]
	e[u - 1] += [(v - 1, w)]
q = queue.Queue()
q.put(0)
d[0] = 0
while not q.empty():
	now = q.get()
	for (to, dis) in e[now]:
		if d[to] == INF:
			d[to] = d[now] + dis
			q.put(to)
for i in d:
	print(i % 2)


import sys
sys.setrecursionlimit(100100)
n = int(input())
route = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	route[u - 1].append((v - 1, w))
	route[v - 1].append((u - 1, w))
ans = [-1] * n

def dfs(p, d):
	ans[p] = d
	for (i, j) in route[p]:
		if ans[i] < 0:
			dfs(i, (d + j) % 2)
dfs(0, 0)
for i in range(n):
	print(ans[i])


import sys

def dfs(u, D):
	sys.setrecursionlimit(10 ** 6)
	for (v, w) in tree[u]:
		if d[v] == -1:
			d[v] = (D + w) % 2
			dfs(v, D + w)
N = int(input())
d = [-1 for _ in range(N)]
d[0] = 0
tree = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	tree[u].append([v, w])
	tree[v].append([u, w])
dfs(0, 0)
for i in d:
	print(i % 2)


import sys
sys.setrecursionlimit(500 * 500)
n = int(input())
l = [list(map(int, input().split())) for _ in range(n - 1)]
g = [[] for _ in range(n)]
for i in l:
	v = i[0] - 1
	y = i[1] - 1
	w = i[2]
	g[v].append([y, w])
	g[y].append([v, w])
seen = [0] + [-1] * (n - 1)

def dfs(s):
	for k in g[s]:
		(v, w) = (k[0], k[1])
		if seen[v] != -1:
			continue
		seen[v] = seen[s] ^ w % 2
		dfs(v)
dfs(0)
for i in seen:
	print(i)


from collections import defaultdict, deque

def bfs(start):
	q = deque([start])
	dist = [-1] * N
	dist[start] = 0
	while q:
		v = q.popleft()
		for (nv, nw) in g[v]:
			if dist[nv] >= 0:
				continue
			dist[nv] = (dist[v] + nw) % 2
			q.append(nv)
	return dist
(N, *UVW) = map(int, open(0).read().split())
g = defaultdict(set)
ans = [0] * N
for (u, v, w) in zip(*[iter(UVW)] * 3):
	u -= 1
	v -= 1
	g[u].add((v, w))
	g[v].add((u, w))
print('\n'.join(map(str, bfs(0))))


def abc126_d():
	import sys
	sys.setrecursionlimit(10010010)
	read = sys.stdin.buffer.read
	inp = iter(map(int, read().split()))
	N = next(inp)
	G = [[] for _ in range(N)]
	for _ in range(N - 1):
		u = next(inp) - 1
		v = next(inp) - 1
		w = next(inp)
		G[u].append((v, w))
		G[v].append((u, w))
	color = [-1] * N
	color[0] = 0

	def dfs(u):
		for (v, w) in G[u]:
			if color[v] != -1:
				continue
			if w % 2 == 0:
				color[v] = color[u]
			else:
				color[v] = abs(color[u] - 1)
			dfs(v)
	dfs(0)
	print(*color, sep='\n')

def __starting_point():
	abc126_d()
__starting_point()


n = int(input())
to_cost = [[] for i in range(n + 1)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	to_cost[u].append([v, w % 2])
	to_cost[v].append([u, w % 2])
ans = [-1] * (n + 1)
stack = [(1, 1)]
while stack:
	(a, w) = stack.pop()
	ans[a] = w
	for (to, cost) in to_cost[a]:
		if ans[to] < 0:
			stack.append((to, w ^ cost))
for a in ans[1:]:
	print(a)


N = int(input())
link = [[] for _ in range(N)]
node = [-1] * N
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	w %= 2
	link[u - 1].append([v - 1, w])
	link[v - 1].append([u - 1, w])
node[0] = 0
q = [0]
while q:
	x = q.pop(0)
	for (i, j) in link[x]:
		if node[i] == -1:
			q.append(i)
			if j == 1:
				node[i] = (node[x] + 1) % 2
			elif j == 0:
				node[i] = node[x]
print(*node, sep='\n')


N = int(input())
(u, v, w) = ([0] * (N - 1), [0] * (N - 1), [0] * (N - 1))
n = [-1] * N
for i in range(N):
	n[i] = [0] * 4
	n[i][1] = []
	n[i][2] = []
for i in range(N - 1):
	(u[i], v[i], w[i]) = list(map(int, input().split()))
	n[u[i] - 1][1].append(v[i] - 1)
	n[v[i] - 1][1].append(u[i] - 1)
	n[u[i] - 1][2].append(w[i] % 2)
	n[v[i] - 1][2].append(w[i] % 2)
stack = [u[0] - 1]
while True:
	num = stack.pop()
	n[num][3] = 1
	for i in range(len(n[num][1])):
		if n[n[num][1][i]][3] == 0:
			stack.append(n[num][1][i])
			if n[num][2][i] == 0:
				n[n[num][1][i]][0] = n[num][0]
			else:
				n[n[num][1][i]][0] = -1 * n[num][0] + 1
	if len(stack) == 0:
		break
for i in n:
	print(i[0])


n = int(input())
L = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	L[u].append([v, w])
	L[v].append([u, w])
ans = [-1] * n
ans[0] = 0
que = [0]
import queue
que = queue.Queue()
que.put(0)
while not que.empty():
	v = que.get()
	for (u, w) in L[v]:
		if ans[u] != -1:
			continue
		ans[u] = (ans[v] + w) % 2
		que.put(u)
for a in ans:
	print(a)


N = int(input())
d = [[] for _ in range(N)]
for i in range(N - 1):
	(v, u, w) = map(int, input().split())
	d[v - 1].append((u - 1, w))
	d[u - 1].append((v - 1, w))
s = [(0, 0)]
l = [-1] * N
while s != []:
	(a, w) = s.pop()
	l[a] = w % 2
	for (i, j) in d[a]:
		if l[i] == -1:
			s.append((i, j + w))
for i in l:
	print(i)


import sys
sys.setrecursionlimit(1000000)

def dfs(color, u):
	for v in conn[u]:
		if not color[v] == -1:
			continue
		color[v] = (color[u] + weight[u, v]) % 2
		dfs(color, v)
N = int(input())
conn = [[] for _ in range(N + 1)]
weight = {}
for _ in range(N - 1):
	(u, v, w) = list(map(int, input().split()))
	conn[u].append(v)
	conn[v].append(u)
	weight[u, v] = w
	weight[v, u] = w
color = [-1] * (N + 1)
color[1] = 0
dfs(color, 1)
for i in range(1, N + 1):
	print(color[i])


from collections import deque
N = int(input())
ki = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	ki[u - 1].append([v - 1, w])
	ki[v - 1].append([u - 1, w])
f = [False] * N
f[0] = True
c = [0] * N
q = deque([0])
while q:
	now = q.popleft()
	for (nxt, w) in ki[now]:
		if f[nxt]:
			continue
		if w & 1:
			c[nxt] = c[now] ^ 1
		else:
			c[nxt] = c[now]
		q.append(nxt)
		f[nxt] = True
for a in c:
	print(a)


import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
edge = [[] for _ in range(n)]
dist = [-1] * n
for i in range(n - 1):
	(x, y, z) = map(int, input().split())
	edge[x - 1].append([y - 1, z])
	edge[y - 1].append([x - 1, z])

def dfs(node, d):
	dist[node] = d
	for i in edge[node]:
		if dist[i[0]] == -1:
			dfs(i[0], d + i[1])
dfs(0, 0)
print(*[i % 2 for i in dist], sep='\n')


import collections
N = int(input())
g = [dict() for _ in range(N + 1)]
for i in range(1, N):
	(u, v, w) = map(int, input().split())
	w = 0 if w % 2 == 0 else 1
	g[u][v] = w
	g[v][u] = w
ret = {1: 0}
q = collections.deque()
q.append(1)
while len(q):
	d = q.pop()
	for h in g[d]:
		if ret.get(h, -1) < 0:
			ret[h] = ret[d] ^ g[d][h]
			q.append(h)
for i in range(1, N + 1):
	print(ret[i])


def main():
	n = int(input())
	ki = {}
	for i in range(1, n + 1):
		ki[i] = []
	for i in range(n - 1):
		(u, v, w) = list(map(int, input().split()))
		ki[u] += [[v, w % 2]]
		ki[v] += [[u, w % 2]]
	cl = [-1 for i in range(n)]
	cl[0] = 0
	que = [0]
	while len(que) > 0:
		q = que.pop(0)
		for v in ki[q + 1]:
			if cl[v[0] - 1] != -1:
				continue
			if v[1] == 1:
				cl[v[0] - 1] = (cl[q] + 1) % 2
				que.append(v[0] - 1)
			else:
				cl[v[0] - 1] = cl[q]
				que.append(v[0] - 1)
	for i in range(n):
		print(cl[i])

def __starting_point():
	main()
__starting_point()


from collections import deque
N = int(input())
dist = {}
graph = [[] for i in range(N)]
for i in range(1, N):
	(u, v, w) = list(map(int, input().split()))
	graph[u - 1].append(v - 1)
	graph[v - 1].append(u - 1)
	dist[u - 1, v - 1] = w
q = deque()
q.append(0)
color = [-1] * N
color[0] = 0
while q:
	now = q.popleft()
	for adj in graph[now]:
		if color[adj] == -1:
			if now < adj:
				color[adj] = color[now] + dist[now, adj]
			else:
				color[adj] = color[now] + dist[adj, now]
			q.append(adj)
for i in range(N):
	print(color[i] % 2)


from collections import deque
N = int(input())
E = {i: {} for i in range(1, N + 1)}
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	E[u][v] = w % 2
	E[v][u] = w % 2
inf = float('inf')
Dist = [inf] * (N + 1)
Q = deque([1])
Dist[1] = 0
while Q:
	u = Q.popleft()
	for v in E[u]:
		if Dist[v] == inf:
			Q.append(v)
			Dist[v] = Dist[u] ^ E[u][v]
print('\n'.join(map(str, Dist[1:])))


N = int(input())
edge = [set() for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	edge[u - 1].add((v - 1, w))
	edge[v - 1].add((u - 1, w))
dist = [0] * N
stack = [0]
while stack:
	vrt = stack.pop()
	for (to, w) in edge[vrt].copy():
		stack.append(to)
		dist[to] = dist[vrt] + w
		edge[vrt].discard((to, w))
		edge[to].discard((vrt, w))
for i in range(N):
	print(dist[i] % 2)


import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
path = [[] for i in range(n)]
for _ in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	path[u - 1].append((v - 1, w))
	path[v - 1].append((u - 1, w))
global dist
dist = [-1 for i in range(n)]
dist[0] = 0

def dfs(now):
	for (v, w) in path[now]:
		if dist[v] == -1:
			dist[v] = w + dist[now]
			dfs(v)
dfs(0)
for i in dist:
	print(i % 2)


import sys
sys.setrecursionlimit(1000000)
n = int(input())
lis = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	lis[u - 1].append((v - 1, w % 2))
	lis[v - 1].append((u - 1, w % 2))
li = [-1] * n

def calc(i, c):
	li[i] = c
	for (j, w) in lis[i]:
		if li[j] < 0:
			calc(j, li[i] ^ w)
calc(0, 0)
for d in li:
	print(d)


N = int(input())
G = [dict() for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	G[u - 1][v - 1] = w
	G[v - 1][u - 1] = w
color = [-1 for i in range(N)]
dist = [-1 for i in range(N)]
dist[0] = 0
q = [0]
while len(q) > 0:
	r = q.pop()
	for p in G[r]:
		if dist[p] != -1:
			continue
		dist[p] = dist[r] + G[r][p]
		q.append(p)
for i in range(N):
	color[i] = dist[i] % 2
for ans in color:
	print(ans)


n = int(input())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	g[u - 1].append((v - 1, w))
	g[v - 1].append((u - 1, w))
from collections import deque
que = deque()
seen = [0] + [-1] * (n - 1)
que.append(0)
while que:
	s = que.popleft()
	for (v, w) in g[s]:
		if seen[v] != -1:
			continue
		seen[v] = seen[s] ^ w % 2
		que.append(v)
for i in seen:
	print(i)


import sys
sys.setrecursionlimit(500 * 500)
n = int(input())
a = [[] for _ in range(n)]
b = [-1] * n
b[0] = 0
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	a[u - 1].append([v - 1, w])
	a[v - 1].append([u - 1, w])

def dfs(A, k):
	for i in A[k]:
		if b[i[0]] == -1:
			b[i[0]] = b[k] + i[1]
			dfs(A, i[0])
dfs(a, 0)
for i in b:
	print(0) if i % 2 == 0 else print(1)


import sys
sys.setrecursionlimit(10 ** 6)
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():

	def dfs(node):
		for adjnode in edges[node]:
			if colors[adjnode[0]] == -1:
				if adjnode[1] % 2 == 0:
					colors[adjnode[0]] = colors[node]
				else:
					colors[adjnode[0]] = colors[node] ^ 1
				dfs(adjnode[0])
	n = int(input())
	edges = {e: [] for e in range(n)}
	for _ in range(n - 1):
		(u, v, w) = map(int, input().split())
		u -= 1
		v -= 1
		edges[u].append((v, w))
		edges[v].append((u, w))
	colors = [-1] * n
	colors[0] = 0
	dfs(0)
	print(*colors, sep='\n')

def __starting_point():
	main()
__starting_point()


import math
import sys
sys.setrecursionlimit(100000)
N = int(input())
edges = [[] for i in range(N + 1)]
d = [-1 for i in range(N + 1)]
for i in range(1, N):
	(u, v, w) = [int(i) for i in input().split()]
	edges[u].append([v, w])
	edges[v].append([u, w])

def kyori(u):
	for (v, w) in edges[u]:
		if d[v] == -1:
			d[v] = d[u] + w
			kyori(v)
d[1] = 0
kyori(1)
for i in d[1:]:
	if i % 2 == 0:
		print(1)
	else:
		print(0)


import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
G = [[] for _ in range(n + 1)]
seen = [-1] * (n + 1)
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	G[u].append([v, w])
	G[v].append([u, w])

def dfs(v, color):
	seen[v] = color
	for (nv, nw) in G[v]:
		if seen[nv] == -1:
			dfs(nv, seen[v] ^ nw % 2)
dfs(1, 0)
for i in seen[1:]:
	print(i)


N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	G[u - 1].append((v - 1, w))
	G[v - 1].append((u - 1, w))
color = [-1] * N
color[0] = 0
import queue
q = queue.Queue()
q.put(0)
while not q.empty():
	v = q.get()
	for (c, w) in G[v]:
		if color[c] >= 0:
			continue
		color[c] = (color[v] + w) % 2
		q.put(c)
print('\n'.join(map(str, color)))


n = int(input())
e = [[] for _ in [0] * -~n]
q = [(1, 0)]
f = [-1] * n
while n > 1:
	(v, w, c) = map(int, input().split())
	e[v] += ((w, c),)
	e[w] += ((v, c),)
	n -= 1
while q:
	(v, c) = q.pop()
	f[v - 1] = c % 2
	for (w, d) in e[v]:
		q += [(w, c + d)] * (f[w - 1] < 0)
print(*f)


g = {}
a = int(input())
for i in range(a - 1):
	c = [int(s) for s in input().split()]
	if c[0] not in g:
		g[c[0]] = [(c[1], c[2])]
	else:
		g[c[0]].append((c[1], c[2]))
	if c[1] not in g:
		g[c[1]] = [(c[0], c[2])]
	else:
		g[c[1]].append((c[0], c[2]))
c = {}
d = {i: False for i in range(1, a + 1)}
(c[1], d[1]) = (0, True)
Q = [1]
while Q != []:
	r = Q.pop(0)
	for i in g[r]:
		if d[i[0]] == False:
			d[i[0]] = True
			Q.append(i[0])
			if i[1] % 2 == 0:
				c[i[0]] = c[r]
			else:
				c[i[0]] = (c[r] + 1) % 2
for i in range(1, a + 1):
	print(c[i])


import sys
sys.setrecursionlimit(10000000)
n = int(input())
s = [[] for i in range(n + 1)]
g = [0] * (n + 1)
h = [True] * (n + 1)
for i in range(n - 1):
	(a, b, c) = map(int, input().split())
	s[a].append([b, c])
	s[b].append([a, c])

def dfs(x):
	h[x] = False
	for i in s[x]:
		if h[i[0]]:
			g[i[0]] = g[x] + i[1]
			dfs(i[0])
dfs(1)
for i in range(1, n + 1):
	if g[i] % 2 == 0:
		print(0)
	else:
		print(1)


import heapq

def dijkstra(G, s, dist):
	dist[s] = 0
	Q = [[0, s]]
	heapq.heapify(Q)
	while len(Q) > 0:
		(cur_d, cur_v) = heapq.heappop(Q)
		cur_d *= -1
		if cur_d > dist[cur_v]:
			continue
		for e in G[cur_v]:
			(to, cost) = (e[0], e[1])
			if dist[cur_v] + cost < dist[to]:
				dist[to] = dist[cur_v] + cost
				heapq.heappush(Q, [-dist[to], to])
N = int(input())
G = [[] for _ in range(N)]
for _ 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])
dist = [1e+18] * N
dijkstra(G, 0, dist)
for d in dist:
	if d % 2 == 0:
		print(0)
	if d % 2 == 1:
		print(1)


N = int(input())
a = [0] * N
b = [[] for _ in range(N)]
for _ in range(N - 1):
	(x, y, z) = map(int, input().split())
	x -= 1
	y -= 1
	b[x].append((y, z))
	b[y].append((x, z))
l = [(0, -1, 0)]
while l:
	(x, s, t) = l.pop()
	if t % 2 == 0:
		a[x] = 0
	else:
		a[x] = 1
	for (v, w) in b[x]:
		if v == s:
			continue
		l.append((v, x, t + w))
for x in a:
	print(x)


n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	w %= 2
	peer[u].append([v, w])
	peer[v].append([u, w])
now = [0]
clr = [-1 for _ in range(n)]
clr[0] = 0
while now:
	last = now
	now = []
	for x in last:
		for y in peer[x]:
			if clr[y[0]] == -1:
				now.append(y[0])
				clr[y[0]] = clr[x] ^ y[1]
for z in clr:
	print(z)


n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	e[u].append((v, w))
	e[v].append((u, w))
res = [-1] * n
res[0] = 0
q = [0]
while len(q):
	v = q.pop()
	for (u, w) in e[v]:
		if res[u] >= 0:
			continue
		res[u] = res[v] + w
		q.append(u)
for r in res:
	print(r % 2)


from collections import deque
n = int(input())
uv = [[] for _ in range(n + 1)]
for i in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	uv[u].append([v, w])
	uv[v].append([u, w])
stack = [1]
ans = [-1] * (n + 1)
ans[1] = 0
while stack:
	x = stack.pop()
	for j in uv[x]:
		if ans[j[0]] == -1:
			if j[1] % 2 == 0:
				ans[j[0]] = ans[x]
			else:
				ans[j[0]] = (ans[x] + 1) % 2
			stack.append(j[0])
for k in range(1, n + 1):
	print(ans[k])


from collections import deque
N = int(input())
g = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = list(map(int, input().split()))
	g[u - 1].append([v - 1, w])
	g[v - 1].append([u - 1, w])
q = deque()
check = [0] * N
check[0] = 1
q.append(0)
ans = [-1] * N
ans[0] = 0
while len(q) > 0:
	e = q.popleft()
	for (i, j) in g[e]:
		if check[i] == 1:
			continue
		ans[i] = (ans[e] + j) % 2
		check[i] = 1
		q.append(i)
for i in range(N):
	print(ans[i])


n = int(input())
tree = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	tree[u].append([v, w])
	tree[v].append([u, w])
d = [-1] * (n + 1)
d[1] = 0
q = [1]
while q:
	now = q.pop()
	for (n_i, n_l) in tree[now]:
		if d[n_i] == -1:
			d[n_i] = d[now] + n_l
			q.append(n_i)
for l in d[1:]:
	print(l % 2)


import sys
sys.setrecursionlimit(100000000)

def dfs(node, distance):
	for (next_node, edge_distangce) in G[node]:
		if ans[next_node] == -1:
			ans[next_node] = (distance + edge_distangce) % 2
			dfs(next_node, distance + edge_distangce)
n = int(input())
G = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	G[u - 1].append([v - 1, w])
	G[v - 1].append([u - 1, w])
ans = [-1] * n
dfs(0, 0)
print(*ans, sep='\n')


n = int(input())
path = [[] for i in range(n)]
for i in range(n - 1):
	(a, b, c) = map(int, input().split())
	path[a - 1].append([b - 1, c % 2])
	path[b - 1].append([a - 1, c % 2])
ans = [-1] * n
ans[0] = 0
q = [0]
while q:
	nq = []
	for k in q:
		for (i, j) in path[k]:
			if ans[i] == -1:
				ans[i] = (ans[k] + j) % 2
				nq.append(i)
	q = nq[:]
for i in ans:
	print(str(i))


import sys
sys.setrecursionlimit(10 ** 9)
N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	G[u].append([v, w])
	G[v].append([u, w])
color = [-1] * N

def dfs(x, y):
	for (i, w) in G[x]:
		if color[i] == -1:
			color[i] = (y + w) % 2
			dfs(i, y + w)
dfs(0, 0)
for i in color:
	print(i)


from collections import deque
INT = lambda : int(input())
INTM = lambda : map(int, input().split())
STRM = lambda : map(str, input().split())
STR = lambda : str(input())
LIST = lambda : list(map(int, input().split()))
LISTS = lambda : list(map(str, input().split()))

class Graph:

	def __init__(self, v):
		self.v = v
		self.graph = [[] for _ in range(v)]
		self.INF = 10 ** 9

	def addEdge(self, start, end, dist):
		self.graph[start].append((end, dist))
		self.graph[end].append((start, dist))

def do():
	n = INT()
	g = Graph(n)
	for i in range(n - 1):
		(u, v, d) = INTM()
		u -= 1
		v -= 1
		g.addEdge(u, v, d)
	que = deque()
	check = [True] * n
	dists = [-1] * n
	check[0] = False
	dists[0] = 0
	que.append([0, 0])
	while que:
		(now, dist_f) = que.popleft()
		for (next, dist) in g.graph[now]:
			if check[next]:
				check[next] = False
				temp = dist_f + dist
				dists[next] = temp
				que.append([next, temp])
	for i in dists:
		if i % 2 == 0:
			print(0)
		else:
			print(1)

def __starting_point():
	do()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
g = [set() for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	g[u - 1].add((v - 1, w % 2))
	g[v - 1].add((u - 1, w % 2))
l = [-1] * n

def dfs(x, p=-1, s=0):
	l[x] = s
	for (c, d) in g[x]:
		if p == c:
			continue
		dfs(c, x, s ^ d)
dfs(0)
print(*l, sep='\n')


import sys
sys.setrecursionlimit(1000000)
N = int(input())
e = [[] for i in range(N + 1)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	e[u].append((v, w))
	e[v].append((u, w))
col = [-1 for i in range(N + 1)]

def dfs(x, c):
	col[x] = c
	for (v, w) in e[x]:
		if col[v] == -1:
			dfs(v, c + w)
dfs(1, 0)
for i in range(1, N + 1):
	print(col[i] % 2)


N = int(input())
from collections import defaultdict
branch = defaultdict(dict)
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	branch[u][v] = w
	branch[v][u] = w
dist = [float('inf')] * N
dist[0] = 0
check = {0}
while len(check) > 0:
	now = check.pop()
	for (nex, d) in branch[now].items():
		if dist[nex] > dist[now] + d:
			dist[nex] = dist[now] + d
			check |= {nex}
for i in range(N):
	print(dist[i] % 2)


n = int(input())
con = [-1] * n
g = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	w %= 2
	g[u].append([v, w])
	g[v].append([u, w])
con[0] = 0
stack = [0]
while stack:
	cur = stack.pop()
	for (i, j) in g[cur]:
		if con[i] == -1:
			con[i] = con[cur] + j
			stack.append(i)
for i in range(n):
	print('01'[con[i] % 2::2])


n = int(input())
l = [[] for _ in range(n + 1)]
q = [(1, 0)]
ans = [-1] * n
while n > 1:
	(u, v, w) = map(int, input().split())
	l[u] += [(v, w)]
	l[v] += [(u, w)]
	n -= 1
while q:
	(u, w) = q.pop()
	ans[u - 1] = w % 2
	for (v, d) in l[u]:
		q += [(v, w + d)] * (ans[v - 1] < 0)
print(*ans)


N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	(u, v) = (u - 1, v - 1)
	T[u].append([v, w])
	T[v].append([u, w])
color = [-1] * N
stack = [[0, 0]]
while stack:
	(n, w) = stack.pop()
	color[n] = w % 2
	for (to, to_w) in T[n]:
		if color[to] >= 0:
			continue
		stack.append([to, w + to_w])
print(*color, sep='\n')


n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	g[u - 1].append((v - 1, w))
	g[v - 1].append((u - 1, w))
distance = [-1] * n
distance[0] = 0
q = [0]
while q:
	p = q.pop()
	for (a, b) in g[p]:
		if distance[a] == -1:
			distance[a] = distance[p] + b
			q.append(a)
for i in range(n):
	print(distance[i] % 2)


import sys
from collections import deque
input = sys.stdin.readline
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))
q = deque()
q.append((0, 0))
color = {}
while q:
	(node, dist) = q.popleft()
	if node in color:
		continue
	if dist % 2 == 0:
		color[node] = 0
	else:
		color[node] = 1
	for (n_node, n_dist) in edges[node]:
		q.append((n_node, dist + n_dist))
for i in range(N):
	print(color[i])


N = int(input())
G = [[] for n in range(N + 1)]
q = [(1, 0)]
ans = N * [-1]
for n in range(N - 1):
	(u, v, w) = map(int, input().split())
	G[u] += [(v, w)]
	G[v] += [(u, w)]
while q:
	(x, y) = q.pop()
	ans[x - 1] = y % 2
	for (g, d) in G[x]:
		q += [(g, y + d)] * (ans[g - 1] < 0)
print(*ans, sep='\n')


import sys
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
sys.setrecursionlimit(10 ** 7)
from collections import deque
INF = 1 << 50
EPS = 1e-08
mod = 998244353

def intread():
	return int(sysread())

def mapline(t=int):
	return list(map(t, sysread().split()))

def mapread(t=int):
	return list(map(t, read().split()))

def dfs(c, num, to, cols):
	for (n, nw) in to[c]:
		if cols[n] == -1:
			y = (num + nw) % 2
			cols[n] = (num + nw) % 2
			dfs(n, y, to, cols)

def run():
	N = intread()
	to = [[] for _ in range(N + 1)]
	for _ in range(N - 1):
		(u, v, w) = mapline()
		to[u].append((v, w))
		to[v].append((u, w))
	cols = [-1] * (N + 1)
	cols[1] = 0
	dfs(1, 0, to, cols)
	for x in cols[1:]:
		print(x)

def __starting_point():
	run()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())

def dfs(s, p):
	nonlocal ans
	for (t, w) in g[s]:
		if t == p or ans[t] >= 0:
			continue
		ans[t] = ans[s] ^ w % 2
		dfs(t, s)
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	g[u].append((v, w))
	g[v].append((u, w))
ans = [-1] * n
ans[0] = 0
dfs(0, -1)
print(*ans, sep='\n')


(N,) = list(map(int, input().split()))
a = [{} for i in range(N)]
for i in range(N - 1):
	(u, v, w) = list(map(int, input().split()))
	u -= 1
	v -= 1
	a[u][v] = w % 2
	a[v][u] = w % 2
r = [-1 for i in range(N)]
r[0] = 0
q = [0]
while q:
	i = q.pop(0)
	for aj in a[i].keys():
		if r[aj] == -1:
			r[aj] = (r[i] + a[i][aj]) % 2
			q.append(aj)
for i in range(N):
	print(r[i])


n = int(input())
s = [None for i in range(n)]
l = [[] for i in range(n)]
for i in range(n - 1):
	(x, y, w) = map(int, input().split())
	x -= 1
	y -= 1
	l[x] += [[y, w % 2]]
	l[y] += [[x, w % 2]]
s[0] = 0
p = [0]
while p:
	q = p.pop()
	for (t, w) in l[q]:
		if s[t] == None:
			if w == 1:
				s[t] = (s[q] + 1) % 2
			else:
				s[t] = s[q]
			p += [t]
for i in s:
	print(i)


from collections import deque
N = int(input())
A = [[] for i in range(N + 1)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	A[u].append([v, w])
	A[v].append([u, w])
check = [-1] * (N + 1)
check[1] = 0
D = deque()
D.append(1)
while D:
	d = D.popleft()
	for a in A[d]:
		if check[a[0]] == -1:
			D.append(a[0])
			check[a[0]] = (check[d] + a[1]) % 2
for i in range(1, len(check)):
	print(check[i])


import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
es = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	es[u - 1].append([v, w])
	es[v - 1].append([u, w])
colors = [0 for i in range(n)]

def dfs(v, color):
	colors[v - 1] = color
	for i in es[v - 1]:
		if i[1] % 2 == 0 and colors[i[0] - 1] == 0:
			dfs(i[0], color)
		elif i[1] % 2 == 1 and colors[i[0] - 1] == 0:
			dfs(i[0], -1 * color)
	return colors
a = dfs(1, -1)
for i in a:
	if i == -1:
		print(0)
	else:
		print(1)


from collections import deque
N = int(input())
visited = [-1] * N
l = [[] for i in range(N)]
for i in range(N - 1):
	(a, b, c) = map(int, input().split())
	a -= 1
	b -= 1
	l[a].append((b, c % 2))
	l[b].append((a, c % 2))

def ans(node, dis):
	visited[node] = 0
	que = deque(l[node])
	while que:
		(node, dis) = que.popleft()
		visited[node] = dis
		for (i, j) in l[node]:
			if visited[i] == -1:
				visited[i] = (dis + j) % 2
				que.append((i, (dis + j) % 2))
ans(0, 0)
for i in visited:
	print(i)


import sys
sys.setrecursionlimit(100000000)

def dfs(node, dist):
	for (nx_node, e_dist) in G[node]:
		if ans[nx_node] == -1:
			ans[nx_node] = (dist + e_dist) % 2
			dfs(nx_node, dist + e_dist)
n = int(input())
G = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	G[u - 1].append([v - 1, w])
	G[v - 1].append([u - 1, w])
ans = [-1] * n
dfs(0, 0)
print(*ans, sep='\n')


n = int(input())
color = [-1] * n
edges = [[] for i in range(n)]
for i 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))
q = [0]
color[0] = 0
while len(q) > 0:
	u = q.pop(0)
	for (v, w) in edges[u]:
		if color[v] < 0:
			q.append(v)
			color[v] = (color[u] + w) % 2
for i in range(n):
	print(color[i])


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
L = [[] for _ in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	w = w % 2
	L[u - 1].append([v, w])
	L[v - 1].append([u, w])
col = [-1] * N

def dfs(p):
	for i in L[p - 1]:
		if col[i[0] - 1] != -1:
			pass
		else:
			col[i[0] - 1] = abs(i[1] - col[p - 1])
			dfs(i[0])
col[0] = 0
dfs(1)
for i in col:
	print(i)


from collections import deque
N = int(input())
length = {}
conn = [[] for _ in range(N + 1)]
for i in range(N - 1):
	(u, v, w) = [int(x) for x in input().split()]
	conn[u].append(v)
	conn[v].append(u)
	length[u, v] = w
q = deque([1])
dist = [-1] * (N + 1)
dist[1] = 0
while q:
	u = q.popleft()
	for v in conn[u]:
		if dist[v] == -1:
			if u < v:
				dist[v] = dist[u] + length[u, v]
			else:
				dist[v] = dist[u] + length[v, u]
			q.append(v)
for i in range(1, N + 1):
	print(dist[i] % 2)


import sys
sys.setrecursionlimit(20000000)

def dfs(node, distance):
	for (next_node, edge_size) in G[node]:
		if ans[next_node] == -1:
			ans[next_node] = (distance + edge_size) % 2
			dfs(next_node, distance + edge_size)
N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	G[u - 1].append([v - 1, w])
	G[v - 1].append([u - 1, w])
ans = [-1] * N
dfs(0, 0)
print(*ans, sep='\n')


import sys
from collections import defaultdict as dd
sys.setrecursionlimit(100000)
N = int(input())
edge = dd(lambda : dd(int))
for _ in range(N - 1):
	(a, b, w) = map(int, input().split())
	edge[a - 1][b - 1] = w
	edge[b - 1][a - 1] = w
ans = [None] * N

def dfs(n, dist):
	ans[n] = dist % 2
	for t in edge[n]:
		if ans[t] is not None:
			continue
		dfs(t, dist + edge[n][t])
dfs(0, 0)
for a in ans:
	print(a)


n = int(input())
g = [set() for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	g[u - 1].add((v - 1, w % 2))
	g[v - 1].add((u - 1, w % 2))
l = [-1] * n
q = [(0, 0)]
while q:
	(a, b) = q.pop()
	l[a] = b
	for (c, d) in g[a]:
		if l[c] >= 0:
			continue
		q += [(c, b ^ d)]
print(*l, sep='\n')


N = int(input())
E = [[] for x in range(N)]
D = [0] * N
L = [0] * N
for i in range(N - 1):
	(u, v, w) = map(int, input().split(' '))
	u -= 1
	v -= 1
	E[u].append([v, w])
	E[v].append([u, w])
q = [[-1, 0, 0]]
while len(q):
	(root, to, dis) = q.pop()
	L[to] = 1
	if root != -1:
		D[to] = D[root] + dis
	for (t, d) in E[to]:
		if L[t]:
			continue
		q.append([to, t, d])
for d in D:
	print(d % 2)


from collections import deque
N = int(input())
vlist = [[] for _ in range(N)]
for i in range(N - 1):
	(a, b, w) = list(map(int, input().split()))
	a -= 1
	b -= 1
	vlist[a].append((b, w))
	vlist[b].append((a, w))
ans = [-1] * N
q = deque()
ans[0] = 0
q.append(0)
while q:
	new = q.popleft()
	for (node, weight) in vlist[new]:
		if ans[node] != -1:
			continue
		ans[node] = (ans[new] + weight) % 2
		q.append(node)
for i in ans:
	print(i)


n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	adj[u - 1].append((w, v - 1))
	adj[v - 1].append((w, u - 1))
paint = [None] * n
paint[0] = 0
stack = [0]
while stack:
	u = stack.pop()
	for (w, v) in adj[u]:
		if paint[v] is None:
			stack.append(v)
			paint[v] = (paint[u] + w) % 2
for p in paint:
	print(p)


N = int(input())
p = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	p[u].append((v, w))
	p[v].append((u, w))
s = [(1, 0)]
l = [-1] * N
while s:
	(a, w) = s.pop()
	l[a - 1] = w % 2
	for (b, c) in p[a]:
		if l[b - 1] == -1:
			s.append((b, w + c))
for i in l:
	print(i)


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	N = I()
	G = [[] for _ in range(N)]
	for _ in range(N - 1):
		(u, v, w) = LI()
		G[u - 1].append((v - 1, w))
		G[v - 1].append((u - 1, w))
	ans = [-1] * N
	ans[0] = 0
	visited = [False] * N

	def dfs(c):
		visited[c] = True
		for (n, w) in G[c]:
			if not visited[n]:
				if w % 2 == 0:
					ans[n] = ans[c]
				else:
					ans[n] = 1 - ans[c]
				dfs(n)
	dfs(0)
	for i in ans:
		print(i)

def __starting_point():
	resolve()
__starting_point()


from collections import deque
N = int(input())
conn = [[] for _ in range(N + 1)]
for i in range(N - 1):
	(u, v, w) = [int(x) for x in input().split()]
	conn[u].append([v, w])
	conn[v].append([u, w])
q = deque([1])
d = [-1] * (N + 1)
d[1] = 0
while q:
	u = q.popleft()
	for e in conn[u]:
		(v, w) = (e[0], e[1])
		if d[v] == -1:
			d[v] = d[u] + w
			q.append(v)
for v in range(1, N + 1):
	print(d[v] % 2)


from collections import deque
N = int(input())
graph = [[] for _ in range(N + 1)]
cost = [[] for _ in range(N + 1)]
ans = [-1] * (N + 1)
for query in range(N - 1):
	(u, v, w) = map(int, input().split())
	graph[u].append(v)
	cost[u].append(w % 2)
	graph[v].append(u)
	cost[v].append(w % 2)
que = deque()
ans[1] = 0
que.append(1)
while que:
	now = que.popleft()
	for index in range(len(graph[now])):
		nextg = graph[now][index]
		nextc = cost[now][index]
		if ans[nextg] != -1:
			continue
		que.append(nextg)
		if nextc == 1:
			ans[nextg] = (ans[now] + 1) % 2
		else:
			ans[nextg] = ans[now]
for i in range(1, N + 1):
	print(ans[i])


n = int(input())
visited = [False] * (n + 1)
distance = [0] * (n + 1)
prev = [0] * (n + 1)
from collections import defaultdict, deque
d = defaultdict(list)
for _ in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	d[u].append((v, w))
	d[v].append((u, w))
q = deque([1])
while q:
	node = q.popleft()
	visited[node] = True
	for (next_node, next_dist) in d[node]:
		if not visited[next_node]:
			q.append(next_node)
			distance[next_node] = distance[node] + next_dist
for dist in distance[1:]:
	print(dist % 2)


from collections import deque, defaultdict
n = int(input())
l = []
dc = [-1] * n
d = defaultdict(list)
for i in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	w %= 2
	d[u - 1].append([v - 1, w])
	d[v - 1].append([u - 1, w])
Q = deque()
Q.append(0)
dc[0] = 0
while Q:
	q = Q.pop()
	for (v, w) in d[q]:
		if dc[v] == -1:
			dc[v] = (dc[q] + w) % 2
			Q.append(v)
for i in dc:
	print(i)


import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n - 1)]
e = [[] for _ in range(n)]
color = [-1] * n
dw = {}
for (u, v, w) in uvw:
	e[u - 1].append(v - 1)
	e[v - 1].append(u - 1)
	dw[u - 1, v - 1] = dw[v - 1, u - 1] = w

def dfs(i, c):
	color[i] = c
	for ei in e[i]:
		if color[ei] != -1:
			continue
		dfs(ei, c + dw[i, ei])
dfs(0, 0)
for c in color:
	print(c % 2)


import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
to = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	to[u].append((v, w))
	to[v].append((u, w))
ans = [-1] * n

def dfs(u=0, c=0, parent=-1):
	ans[u] = c
	for (v, w) in to[u]:
		if v == parent:
			continue
		dfs(v, c + w & 1, u)
dfs()
print(*ans, sep='\n')


N = int(input())
S = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	S[u - 1].append((v - 1, w))
	S[v - 1].append((u - 1, w))
C = [-1] * N
Q = [0]
C[0] = 0
while Q:
	p = Q.pop()
	Ns = S[p]
	for (v, w) in Ns:
		if C[v] < 0:
			C[v] = (C[p] + w) % 2
			Q.append(v)
for i in range(N):
	print(C[i])


import sys
sys.setrecursionlimit(10 ** 5)

def f(x):
	for tmp in links[x]:
		if c[tmp[0]] < 0:
			if tmp[1] % 2 == 0:
				c[tmp[0]] = c[x] + 0
			else:
				c[tmp[0]] = 1 - c[x]
			f(tmp[0])
N = int(input())
links = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	links[u].append([v, w])
	links[v].append([u, w])
c = [-1] * (N + 1)
c[1] = 0
f(1)
print(*c[1:], sep='\n')


import collections
n = int(input())
graph = [[] for i in range(n + 1)]
flag = [False for i in range(n + 1)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	graph[u].append([v, w])
	graph[v].append([u, w])
color = [None for i in range(n + 1)]
color[1] = 0
queue = collections.deque([1])
while queue:
	test = queue.popleft()
	flag[test] = True
	for i in graph[test]:
		if flag[i[0]] == True:
			continue
		queue.append(i[0])
		color[i[0]] = i[1] % 2 ^ color[test]
for i in range(n):
	print(color[i + 1])


n = int(input())
uvw = [list(map(int, input().split())) for i in range(n - 1)]
graph = [[] for i in range(n + 1)]
color = [-1] * (n + 1)
for (u, v, w) in uvw:
	graph[u].append((v, w))
	graph[v].append((u, w))
color[1] = 1
ne = [1]
while ne:
	t = ne.pop()
	for (v, w) in graph[t]:
		if color[v] == -1:
			ne.append(v)
			color[v] = color[t] if w % 2 == 0 else (color[t] + 1) % 2
for i in range(1, n + 1):
	print(color[i])


import sys
sys.setrecursionlimit(100000)
N = int(input())
tree = [[] for i in range(N)]
color = [-1] * N
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	tree[u - 1].append((v - 1, w))
	tree[v - 1].append((u - 1, w))

def dfs(u):
	for (v, w) in tree[u]:
		if color[v] == -1:
			color[v] = color[u] ^ w % 2
			dfs(v)
color[0] = 0
dfs(0)
print('\n'.join(map(str, color)))


n = int(input())
L = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	L[u].append([v, w])
	L[v].append([u, w])
ans = [-1] * n
ans[0] = 0
que = [0]
while que:
	v = que.pop()
	for (u, w) in L[v]:
		if ans[u] != -1:
			continue
		ans[u] = (ans[v] + w) % 2
		que.append(u)
for a in ans:
	print(a)


N = int(input())
G = [[] for _ in [0] * (N + 1)]
for _ in [0] * (N - 1):
	(u, v, w) = map(int, input().split())
	G[u].append((v, w))
	G[v].append((u, w))
c = [0] * (N + 1)
stack = [1]
c[1] = 1
while stack:
	r = stack.pop()
	for (nr, nw) in G[r]:
		if c[nr] == 0:
			stack.append(nr)
			if nw % 2:
				c[nr] = -c[r]
			else:
				c[nr] = c[r]
for i in c[1:]:
	print((i + 1) // 2)


from collections import deque
n = int(input())
ad_ls = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b, w) = list(map(int, input().split()))
	ad_ls[a - 1].append([b - 1, w])
	ad_ls[b - 1].append([a - 1, w])
cost_ls = [0] * n
done_ls = [0] * n
done_ls[0] = 1
q = deque()
q.append(0)
while q:
	now = q.pop()
	for new in ad_ls[now]:
		(nex, cost) = (new[0], new[1])
		if not done_ls[nex]:
			cost_ls[nex] = cost + cost_ls[now]
			done_ls[nex] = 1
			q.append(nex)
color_ls = [0] * n
for i in range(n):
	color_ls[i] = cost_ls[i] % 2
for color in color_ls:
	print(color)


n = int(input())
tree = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	tree[u - 1].append((v - 1, w))
	tree[v - 1].append((u - 1, w))
color = [-1] * n
color[0] = 0
q = [0]
while q:
	x = q.pop()
	for (t, cost) in tree[x]:
		if color[t] >= 0:
			continue
		if cost % 2 == 0:
			color[t] = color[x]
		else:
			color[t] = 1 - color[x]
		q.append(t)
print(*color, sep='\n')


import sys, math, collections, itertools
input = sys.stdin.readline
N = int(input())
road = [[] for i in range(N + 1)]
for _ in range(N - 1):
	(u, v, w) = list(map(int, input().split()))
	road[u].append((v, w))
	road[v].append((u, w))
dist = [float('inf') for i in range(N + 1)]
ans = [0] * (N + 1)
q = collections.deque([])
q.append(1)
dist[1] = 0
while q:
	now = q.popleft()
	for (goto, cost) in road[now]:
		if dist[goto] > dist[now] + cost:
			dist[goto] = dist[now] + cost
			q.append(goto)
for a in dist[1:]:
	print(a % 2)


n = int(input())
d = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	d[u - 1].append([v - 1, w])
	d[v - 1].append([u - 1, w])
ans = [-1] * n
ans[0] = 0
q = [0]
cnt = 0
while q:
	u = q.pop()
	for (v, w) in d[u]:
		if ans[v] == -1:
			if w % 2 == 0:
				ans[v] = ans[u]
			else:
				ans[v] = (ans[u] + 1) % 2
			q.append(v)
for i in ans:
	print(i)


n = int(input())
uv = [[] for _ in range(n + 1)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	uv[u].append([v, w])
	uv[v].append([u, w])
stack = [1]
ans = [-1] * (n + 1)
ans[1] = 0
while stack:
	x = stack.pop()
	for (j, k) in uv[x]:
		if ans[j] == -1:
			if k % 2 == 0:
				ans[j] = ans[x]
			else:
				ans[j] = (ans[x] + 1) % 2
			stack.append(j)
for m in range(n):
	print(ans[m + 1])


n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	(u, v) = (u - 1, v - 1)
	g[u].append((v, w))
	g[v].append((u, w))
color = [-1] * n
color[0] = 0
import queue
q = queue.Queue()
q.put(0)
while not q.empty():
	now = q.get()
	for (ne, weight) in g[now]:
		if color[ne] != -1:
			continue
		if weight % 2 == 0:
			color[ne] = color[now]
		else:
			color[ne] = abs(color[now] - 1)
		q.put(ne)
for i in range(n):
	print(color[i])


n = int(input())
e = [list() for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	e[u - 1] += [[v, w]]
	e[v - 1] += [[u, w]]
visited = [-1] * n
stack = [0]
visited[0] = 0
while stack:
	z = stack.pop()
	for (v, w) in e[z]:
		if visited[v - 1] == -1:
			stack.append(v - 1)
			if w % 2 == 0:
				visited[v - 1] = visited[z]
			else:
				visited[v - 1] = 1 - visited[z]
		else:
			continue
print(*visited, sep='\n')


def inpl():
	return list(map(int, input().split()))
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = inpl()
	G[u - 1].append((v - 1, w))
	G[v - 1].append((u - 1, w))
Q = [(0, 0)]
searched = [0] * N
searched[0] = 1
ans = [-1] * N
ans[0] = 0
while Q:
	(p, c) = Q.pop()
	for (q, d) in G[p]:
		if searched[q]:
			continue
		ans[q] = (c + d) % 2
		searched[q] = 1
		Q.append((q, ans[q]))
print(*ans, sep='\n')


import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	g[u - 1].append((v - 1, w))
	g[v - 1].append((u - 1, w))
ans = [0] * n

def dfs(v, p, c):
	ans[v] = c
	for i in g[v]:
		if i[0] != p:
			if i[1] % 2 == 0:
				dfs(i[0], v, c)
			else:
				dfs(i[0], v, 1 - c)
dfs(0, -1, 0)
for i in ans:
	print(i)


N = int(input())
graph = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b, w) = map(int, input().split())
	graph[a].append([b, w])
	graph[b].append([a, w])
color = [-1] * (N + 1)
color[1] = 0
ne = [1]
while ne != []:
	t = ne.pop()
	for (s, w) in graph[t]:
		if color[s] == -1:
			ne.append(s)
			color[s] = color[t] if w % 2 == 0 else (color[t] + 1) % 2
print(*color[1:], sep='\n')


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	edges[u - 1].append((w, v - 1))
	edges[v - 1].append((w, u - 1))
color = [-1] * n

def dfs(v, d, parent):
	color[v] = d & 1
	for (d2, v2) in edges[v]:
		if v2 == parent:
			continue
		dfs(v2, d + d2, v)
dfs(0, 0, -1)
print(*color, sep='\n')


import collections
n = int(input())
way = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	u -= 1
	v -= 1
	way[u].append((v, w))
	way[v].append((u, w))
visited = [False] * n
ans = [0] * n
q = collections.deque()
q.append(0)
while len(q) > 0:
	c = q.popleft()
	visited[c] = True
	for next in way[c]:
		if not visited[next[0]]:
			ans[next[0]] = (ans[c] + next[1]) % 2
			q.append(next[0])
for i in ans:
	print(i)


N = int(input())
uvw = [[int(_) for _ in input().split()] for i in range(N - 1)]
from collections import defaultdict
uv = defaultdict(dict)
for (u, v, w) in uvw:
	uv[u][v] = w
	uv[v][u] = w
l = {1: 0}
s = [1]
while s:
	ns = []
	for i in s:
		for j in uv[i]:
			if not j in l:
				l[j] = l[i] + uv[i][j]
				ns.append(j)
	s = ns
for i in range(1, N + 1):
	print(l[i] % 2)


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
ad = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	ad[u].append((v, w))
	ad[v].append((u, w))
color = [-1] * N

def dfs(v=0, pv=-1, d=0):
	color[v] = d % 2
	for (nv, nw) in ad[v]:
		if nv == pv:
			continue
		nd = d + nw
		dfs(nv, v, nd)
dfs()
for c in color:
	print(c)


import sys
sys.setrecursionlimit(10 ** 9)
N = int(input())
to = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	(u, v) = (u - 1, v - 1)
	to[u].append([v, w])
	to[v].append([u, w])

def dfs(v, color):
	for (nv, w) in to[v]:
		if color[nv] == -1:
			if w % 2:
				color[nv] = color[v] ^ 1
			else:
				color[nv] = color[v]
			dfs(nv, color)

def main():
	color = [-1] * N
	color[0] = 0
	dfs(0, color)
	print(*color, sep='\n')

def __starting_point():
	main()
__starting_point()


n = int(input())
q = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b, c) = map(int, input().split())
	q[a].append((b, c))
	q[b].append((a, c))
l = [-1] * n
s = [(1, 0)]
while s:
	(a, w) = s.pop()
	l[a - 1] = w % 2
	for (b, c) in q[a]:
		if l[b - 1] == -1:
			s.append((b, w + c))
for i in l:
	print(i)


n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n - 1)]
adj = [[] for _ in range(n)]
for (u, v, w) in uvw:
	u -= 1
	v -= 1
	adj[u].append([v, w])
	adj[v].append([u, w])
stack = [0]
d = [-1] * n
d[0] = 0
while stack:
	u = stack.pop()
	for (v, w) in adj[u]:
		if d[v] == -1:
			d[v] = d[u] + w
			d[v] %= 2
			stack.append(v)
print(*d, sep='\n')


N = int(input())
graph = [[] for _ in range(N)]
color = [-1] * N
for i in range(N - 1):
	(a, b, w) = map(int, input().split())
	a -= 1
	b -= 1
	w %= 2
	graph[a].append((b, w))
	graph[b].append((a, w))
next_q = [(0, 0)]
while len(next_q) > 0:
	(nw, nc) = next_q.pop()
	color[nw] = nc
	for (nxt, nl) in graph[nw]:
		if color[nxt] == -1:
			next_q.append((nxt, (nl + nc) % 2))
for i in color:
	print(i)


import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def dfs(d, v, p):
	if d & 1:
		C[v] = 1
	for (w, u) in E[v]:
		if u == p:
			continue
		dfs(d ^ w, u, v)
N = int(input())
C = [0] * N
E = [[] for _ in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	E[u].append((w % 2, v))
	E[v].append((w % 2, u))
dfs(0, 0, -1)
print(*C, sep='\n')


(N,) = map(int, input().split())
import sys
sys.setrecursionlimit(10 ** 6)
d = [set() for _ in range(N + 1)]
Cs = [0 for _ in range(N + 1)]
for _ in range(N - 1):
	(u, v, p) = map(int, input().split())
	d[u].add((v, p))
	d[v].add((u, p))

def it(v, p):
	for (u, c) in d[v]:
		if u == p:
			continue
		Cs[u] = int(not Cs[v]) if c % 2 else Cs[v]
		it(u, v)
it(1, None)
for i in range(1, N + 1):
	print(Cs[i])


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
Graph = [[] for _ in range(N + 10)]
dist = [10000000000000] * (N + 10)
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	Graph[u].append((v, w))
	Graph[v].append((u, w))
dist[0] = 0

def func(fromE, now, length):
	if fromE != -1:
		dist[now] = dist[fromE] + length
	for i in range(len(Graph[now])):
		target = Graph[now][i][0]
		lengt = Graph[now][i][1]
		if target == fromE:
			continue
		func(now, target, lengt)
func(-1, 0, 0)
for i in range(N):
	if dist[i] % 2 == 0:
		print(0)
	else:
		print(1)


import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
l = [-1] * n
p = [[] for _ in range(n)]
for i in range(n - 1):
	(ui, vi, wi) = map(int, input().split())
	p[ui - 1].append([vi, wi])
	p[vi - 1].append([ui, wi])

def tr1(x, y):
	if l[x - 1] != -1:
		return
	l[x - 1] = y
	for i in range(len(p[x - 1])):
		tr1(p[x - 1][i][0], (y + p[x - 1][i][1]) % 2)
tr1(1, 0)
for j in range(n):
	print(l[j])


from collections import deque
n = int(input())
e = [[] for _ in range(n + 1)]
c = [-1] * (n + 1)
for _ in range(n - 1):
	(a, b, w) = map(int, input().split())
	e[a] += [(b, w)]
	e[b] += [(a, w)]
q = deque([1])
c[1] = 0
while q:
	now = q.popleft()
	for (to, w) in e[now]:
		if c[to] == -1:
			c[to] = (c[now] + w) % 2
			q.append(to)
print(*c[1:], sep='\n')


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
A = [list(map(int, input().split())) for _ in range(N - 1)]
C = [0] * N
D = [[] for i in range(N)]
for (u, v, w) in A:
	u -= 1
	v -= 1
	D[u].append((v, w))
	D[v].append((u, w))

def dfs(n, v, k):
	for i in D[n]:
		if k % 2 != 0:
			C[n] = 1
		if v != i[0]:
			dfs(i[0], n, k + i[1])
dfs(0, 0, 0)
for i in C:
	print(i)


import sys
sys.setrecursionlimit(500 * 500)
N = int(input())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N + 1)]
for edge in edges:
	tree[edge[0]].append([edge[1], edge[2]])
	tree[edge[1]].append([edge[0], edge[2]])
depth = [-1] * (N + 1)
depth[1] = 0

def dfs(tree, s):
	for l in tree[s]:
		if depth[l[0]] == -1:
			depth[l[0]] = depth[s] + l[1]
			dfs(tree, l[0])
dfs(tree, 1)
for l in depth[1:]:
	if l % 2 == 0:
		print(1)
	else:
		print(0)


n = int(input())
vs = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	vs[u - 1].append((v - 1, w))
	vs[v - 1].append((u - 1, w))
stack = [0]
color = [-1] * n
color[0] = 0
while stack:
	v = stack.pop()
	for (b, w) in vs[v]:
		if color[b] == -1:
			color[b] = (color[v] + w) % 2
			stack.append(b)
print(*color, sep='\n')


n = int(input())
edges = [set() for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = [int(i) - 1 for i in input().split()]
	edges[u].add((v, w + 1))
	edges[v].add((u, w + 1))
ans = [-1] * n
q = [(0, 0, -1)]
while q:
	(v, d, p) = q.pop()
	if d % 2 == 0:
		ans[v] = 0
	else:
		ans[v] = 1
	for (u, w) in edges[v]:
		if u == p:
			continue
		q.append((u, d + w, v))
for i in range(n):
	print(ans[i])


from collections import defaultdict
N = int(input())
E = defaultdict(list)
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	E[u].append((v, w))
	E[v].append((u, w))
ans = [-1] * N
stack = [0]
ans[0] = 0
while stack:
	node = stack.pop()
	for (to, w) in E[node]:
		if ans[to] != -1:
			continue
		ans[to] = ans[node] ^ w & 1
		stack.append(to)
for c in ans:
	print(c)


from collections import deque
N = int(input())
G = [{} for _ in range(N + 1)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	G[u][v] = w
	G[v][u] = w
for i in range(1, N + 1):
	if len(G[i]) == 1:
		start = i
		break

def bfs(s):
	seen = [0 for i in range(N + 1)]
	d = [0 for i in range(N + 1)]
	todo = deque([])
	now = s
	seen[now] = 1
	todo.append(now)
	while 1:
		if len(todo) == 0:
			break
		a = todo.popleft()
		for b in G[a]:
			if seen[b] == 0:
				seen[b] = 1
				todo.append(b)
				d[b] += d[a] + G[a][b]
	return d
d = bfs(start)
for i in range(1, N + 1):
	d_ = d[i]
	if d_ % 2 == 0:
		print(0)
	else:
		print(1)


import sys
sys.setrecursionlimit(1000000)
n = int(input())
tree = [[] for _ in range(n)]
color = [0] * n
for _ in range(n - 1):
	(a, b, c) = map(int, input().split())
	a -= 1
	b -= 1
	tree[a].append((b, c))
	tree[b].append((a, c))

def dfs(i, before, cost):
	if cost == 1:
		color[i] = 1
	for j in tree[i]:
		if j[0] == before:
			continue
		dfs(j[0], i, (cost + j[1]) % 2)
dfs(0, -1, 0)
for i in range(n):
	print(color[i])


N = int(input())
INF = float('inf')
dis = [INF] * N
dis[0] = 0
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	G[u].append((v, w))
	G[v].append((u, w))
queue = [0]
while queue:
	u = queue.pop()
	for (v, w) in G[u]:
		if dis[v] > dis[u] + w:
			queue.append(v)
			dis[v] = dis[u] + w
for i in dis:
	print(i % 2)


N = int(input())
to = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = [int(x) for x in input().split()]
	u -= 1
	v -= 1
	to[u].append([v, w])
	to[v].append([u, w])
ans = [-1] * N
ans[0] = 0
q = [0]
while len(q) != 0:
	v = q.pop()
	for (u, w) in to[v]:
		if ans[u] != -1:
			continue
		ans[u] = (ans[v] + w) % 2
		q.append(u)
for v in ans:
	print(v)


n = int(input())
g = [[] for i in range(n)]
c = [-1 for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	g[u].append([v, w])
	g[v].append([u, w])
q = [0]
while len(q) > 0:
	v = q.pop()
	for (u, w) in g[v]:
		if c[u] != -1:
			continue
		q.append(u)
		c[u] = (c[v] + w) % 2
for v in c:
	print(v)


n = int(input())
(x, ans, q) = ([[] for i in range(n + 1)], [-1] * (n + 1), [])
for i in range(n - 1):
	(u, v, w) = (int(i) for i in input().split())
	x[u].append((v, w % 2))
	x[v].append((u, w % 2))
for (i, j) in x[1]:
	q.append((i, 1, j))
ans[1] = 0
while q:
	(i, p, d) = q.pop()
	ans[i] = abs(d - ans[p])
	for (j, k) in x[i]:
		if ans[j] == -1:
			q.append((j, i, k))
for i in ans[1:]:
	print(i)


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = list(map(int, input().split()))
	u -= 1
	v -= 1
	graph[u].append([v, w])
	graph[v].append([u, w])
color = [-1] * N

def even(v=0, col=0):
	color[v] = col
	for i in range(len(graph[v])):
		(nv, nw) = list(map(int, graph[v][i]))
		if color[nv] != -1:
			continue
		if nw % 2 == 0:
			even(nv, col)
		else:
			even(nv, 1 - col)
even()
for i in range(N):
	print(color[i])


from collections import deque

def bfs(s):
	nonlocal color
	q = deque()
	q.append(s)
	color[s] = 0
	while q:
		i = q.popleft()
		for g in G[i]:
			if color[g[0]] == -1:
				if g[1] % 2 == 0:
					color[g[0]] = color[i]
				else:
					color[g[0]] = 1 - color[i]
				q.append(g[0])
	return
n = int(input())
G = [[] for _ in range(n + 1)]
color = [-1] * (n + 1)
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	G[u].append([v, w])
	G[v].append([u, w])
bfs(1)
for i in range(1, n + 1):
	print(color[i])


import sys
sys.setrecursionlimit(10 ** 7)

def dfs(s, to, color):
	for (next_v, step) in to[s]:
		if color[next_v] == -1:
			if step % 2 == 0:
				color[next_v] = color[s]
			else:
				color[next_v] = color[s] ^ 1
			dfs(next_v, to, color)

def solve():
	N = int(input())
	to = [[] for _ in range(N)]
	for _ in range(N - 1):
		(u, v, w) = map(int, input().split())
		(u, v) = (u - 1, v - 1)
		to[u].append([v, w])
		to[v].append([u, w])
	color = [-1] * N
	color[0] = 0
	dfs(0, to, color)
	print(*color, sep='\n')

def __starting_point():
	solve()
__starting_point()


n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
	(xi, yi, wi) = map(int, input().split())
	xi -= 1
	yi -= 1
	e[yi].append((xi, wi))
	e[xi].append((yi, wi))
c = [0] * n
used = [0] * n
from collections import deque
q = deque()
q.append(0)
while q:
	u = q.popleft()
	for (v, w) in e[u]:
		if not used[v]:
			c[v] = (c[u] + w) % 2
			used[v] = 1
			q.append(v)
for i in c:
	print(i)


import sys
from heapq import heappush, heappop
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, *UVW) = map(int, read().split())
	G = [[] for _ in range(N)]
	for (u, v, w) in zip(*[iter(UVW)] * 3):
		G[u - 1].append((v - 1, w))
		G[v - 1].append((u - 1, w))
	dist = [INF] * N
	dist[0] = 0
	hq = [(0, 0)]
	while hq:
		(d, v) = heappop(hq)
		if d > dist[v]:
			continue
		for (nv, cost) in G[v]:
			if dist[nv] > dist[v] + cost:
				dist[nv] = dist[v] + cost
				heappush(hq, (dist[nv], nv))
	ans = [0] * N
	for i in range(N):
		ans[i] = 0 if dist[i] % 2 == 0 else 1
	print(*ans, sep='\n')
	return

def __starting_point():
	main()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
path = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	path[u - 1].append((v - 1, w % 2))
	path[v - 1].append((u - 1, w % 2))
ans = [0] + [-1] * (n - 1)

def dfs(i):
	nonlocal n, path, ans
	for j in path[i]:
		if ans[j[0]] == -1:
			if j[1]:
				ans[j[0]] = 1 - ans[i]
				dfs(j[0])
			else:
				ans[j[0]] = ans[i]
				dfs(j[0])
dfs(0)
print('\n'.join(map(str, ans)))


N = int(input())
dist_from_1 = [0 for i in range(N + 1)]
paths = [dict() for i in range(N + 1)]
for i in range(N - 1):
	(a, b, dist) = list(map(int, input().split()))
	paths[a][b] = dist
	paths[b][a] = dist
queue = [(0, 1, 0)]
while len(queue) != 0:
	(prev, now, dist) = queue.pop()
	dist_from_1[now] = dist
	for next in paths[now]:
		if next == prev:
			continue
		queue.append((now, next, dist + paths[now][next]))
for i in range(1, N + 1):
	if dist_from_1[i] % 2 == 0:
		print(0)
	else:
		print(1)


from collections import deque
n = int(input())
ch = 0
g = [[] for _ in range(n)]
k = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	if w % 2 == 0:
		g[u - 1].append(v - 1)
		g[v - 1].append(u - 1)
	else:
		k[u - 1].append(v - 1)
		k[v - 1].append(u - 1)
		ch1 = u - 1
		ch2 = v - 1
		ch = 1
ans = [-1 for _ in range(n)]
if ch > 0:
	ans[ch1] = 0
	d = [ch1]
	qu = deque(d)
	while qu:
		p = qu.popleft()
		for gr in g[p]:
			if ans[gr] == -1:
				if ans[p] == 0:
					ans[gr] = 0
					qu.append(gr)
				else:
					ans[gr] = 1
					qu.append(gr)
		for kr in k[p]:
			if ans[kr] == -1:
				if ans[p] == 0:
					ans[kr] = 1
					qu.append(kr)
				else:
					ans[kr] = 0
					qu.append(kr)
	for j in range(n):
		print(ans[j])
else:
	for j in range(n):
		print(0)


n = int(input())
lines = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	lines[u].append([v, w])
	lines[v].append([u, w])
ans = [0 for i in range(n)]
q = [[0, 0, -1]]
while q:
	(u, w, v) = q.pop(0)
	if w % 2 == 0:
		ans[u] = 0
	else:
		ans[u] = 1
	for (n, ww) in lines[u]:
		if n == v:
			continue
		q.append([n, w + ww, u])
for a in ans:
	print(a)


N = int(input())
src = [tuple(map(int, input().split())) for i in range(N - 1)]
es = [[] for i in range(N)]
for (u, v, w) in src:
	(u, v) = (u - 1, v - 1)
	es[u].append((v, w))
	es[v].append((u, w))
visited = [0] * N
visited[0] = 1
ans = [0] * N
stack = [0]
while stack:
	v = stack.pop()
	for (to, c) in es[v]:
		if visited[to]:
			continue
		ans[to] = (ans[v] + c) % 2
		visited[to] = 1
		stack.append(to)
print(*ans, sep='\n')


import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
N = int(input())
G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(v, u, w) = map(int, input().split())
	G[v].append((u, w))
	G[u].append((v, w))
deq = deque()
deq.append(1)
res = [-1] * (N + 1)
res[1] = 0
while deq:
	x = deq.popleft()
	for (e, w) in G[x]:
		if res[e] == -1:
			res[e] = (res[x] + w) % 2
			deq.append(e)
[print(r) for r in res[1:]]


from collections import deque
N = int(input())
vw = [[] for _ in range(N)]
for i in range(N - 1):
	(a, b, w) = map(int, input().split())
	vw[a - 1].append((b - 1, w))
	vw[b - 1].append((a - 1, w))
ans = [-1] * N
q = deque([(0, 0)])
while q:
	(a, w) = q.popleft()
	ans[a] = w % 2
	for (b, c) in vw[a]:
		if ans[b] == -1:
			q.append((b, w + c))
print('\n'.join(map(str, ans)))


import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
tree = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	tree[u - 1].append((v - 1, w))
	tree[v - 1].append((u - 1, w))
ans = [-1] * N
ans[0] = 0
d = deque([0])
while d:
	p = deque.popleft(d)
	color = ans[p]
	for (v, w) in tree[p]:
		if ans[v] == -1:
			deque.append(d, v)
			ans[v] = color ^ w % 2
print(*ans, sep='\n')


N = int(input())
tree = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	tree[u - 1].append((v - 1, w))
	tree[v - 1].append((u - 1, w))
h = []
h.append(0)
distance = [-1 for i in range(N)]
distance[0] = 0
while h:
	k = h.pop(0)
	for v in tree[k]:
		x = v[0]
		y = v[1]
		if distance[x] == -1:
			distance[x] = distance[k] + y
			h.append(x)
for i in range(N):
	if distance[i] % 2 == 0:
		print(0)
	else:
		print(1)


n = int(input())
li = [[] for _ in range(n + 1)]
q = [(1, 0)]
ans = [-1] * n
while n > 1:
	(s, g, c) = map(int, input().split())
	li[s] += [(g, c)]
	li[g] += [(s, c)]
	n -= 1
while q:
	(s, c) = q.pop()
	ans[s - 1] = c % 2
	for (g, d) in li[s]:
		q += [(g, c + d)] * (ans[g - 1] < 0)
print(*ans)


from collections import deque
N = int(input())
E = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	E[u - 1].append((v - 1, w))
	E[v - 1].append((u - 1, w))
ans = [-1] * N
ans[0] = 0
q = deque([0])
while q:
	next = q.popleft()
	for (u, w) in E[next]:
		if ans[u] < 0:
			q.append(u)
			ans[u] = int(ans[next]) if w % 2 == 0 else int(not ans[next])
print(*ans)


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')


import sys
sys.setrecursionlimit(1000000)
N = int(input())
X = [[] for _ in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	X[u - 1].append((v - 1, w % 2))
	X[v - 1].append((u - 1, w % 2))
D = [-1] * N

def calc(i, c):
	D[i] = c
	for (j, w) in X[i]:
		if D[j] < 0:
			calc(j, D[i] ^ w)
calc(0, 0)
for d in D:
	print(d)


N = int(input())
links = [set() for _ in [0] * N]
for i in range(1, N):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	links[u].add((v, w))
	links[v].add((u, w))
ans = [-1] * N
q = [(0, 0, -1)]
while q:
	(v, d, p) = q.pop()
	if d % 2 == 0:
		ans[v] = 0
	else:
		ans[v] = 1
	for (u, w) in links[v]:
		if u == p:
			continue
		q.append((u, w + d, v))
print('\n'.join(map(str, ans)))


from collections import defaultdict, deque
N = int(input())
G = {}
for i in range(1, N + 1):
	G[i] = []
for i in range(N - 1):
	(u, v, w) = (int(n) for n in input().split())
	G[u].append((v, w))
	G[v].append((u, w))
ret = [-1] * (N + 1)
que = deque()
que.append((1, 0))
while len(que) > 0:
	(node, distance) = que[0]
	que.popleft()
	ret[node] = distance % 2
	for (next_node, next_distance) in G[node]:
		if ret[next_node] == -1:
			que.append((next_node, distance + next_distance))
for i in range(N):
	print(ret[i + 1])


N = int(input())
ans = [-1] * N
ans[0] = 0
root = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = list(map(int, input().split()))
	root[u - 1].append([v - 1, w])
	root[v - 1].append([u - 1, w])
visited = [0] * N
visited[0] = 1
queue = [0]
while queue:
	x = queue.pop()
	for (i, value) in root[x]:
		if value % 2 == 0:
			ans[i] = ans[x]
		else:
			ans[i] = abs(1 - ans[x])
		if visited[i] == 0:
			visited[i] = 1
			queue.append(i)
for i in range(N):
	print(ans[i])


import sys
sys.setrecursionlimit(500000)

def dfs(v, w, c):
	if w % 2 == 1:
		c = 1 - c
	color[v] = c
	for i in a[v]:
		if color[i[0]] != -1:
			continue
		dfs(i[0], i[1], c)
n = int(input())
a = [[] for i in range(n)]
color = [-1 for _ in range(n)]
for i in range(n - 1):
	(x, y, z) = map(int, input().split())
	a[x - 1].append([y - 1, z])
	a[y - 1].append([x - 1, z])
dfs(a[0][0][0], a[0][0][1], 0)
print(*color, sep='\n')


import sys
sys.setrecursionlimit(10 ** 7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor

def cmb(n, r, mod):
	bunshi = 1
	bunbo = 1
	for i in range(r):
		bunbo = bunbo * (i + 1) % mod
		bunshi = bunshi * (n - i) % mod
	return bunshi * pow(bunbo, mod - 2, mod) % mod
mod = 10 ** 9 + 7

def I():
	return int(input())

def LI():
	return list(map(int, input().split()))

def MI():
	return list(map(int, input().split()))

def LLI(n):
	return [list(map(int, input().split())) for _ in range(n)]
n = I()
graph = [[] * (n + 1) for i in range(n + 1)]
ans = [0] * (n + 1)
for i in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	w = w % 2
	graph[u].append([v, w])
	graph[v].append([u, w])

def dfs(v, p, c, ans):
	ans[v] = c
	for i in graph[v]:
		if i[0] == p:
			continue
		if i[1] == 1:
			dfs(i[0], v, 1 - c, ans)
		if i[1] == 0:
			dfs(i[0], v, c, ans)
dfs(1, 0, 0, ans)
for i in ans[1:]:
	print(i)


import sys
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

def search(nodes, searched, labels, v):
	searched[v] = 1
	label = labels[v]
	for l in nodes[v]:
		(x, w) = l
		if not searched[x]:
			if w % 2 == 0:
				labels[x] = label
			else:
				labels[x] = (label + 1) % 2
			search(nodes, searched, labels, x)

def solve(n, nodes):
	searched = [0] * n
	labels = [None] * n
	labels[0] = 0
	search(nodes, searched, labels, 0)
	return labels

def main():
	n = int(input())
	nodes = [[] for _ in range(n)]
	for _ in range(n - 1):
		(v, u, w) = map(int, input().split(' '))
		nodes[v - 1].append((u - 1, w))
		nodes[u - 1].append((v - 1, w))
	ans = solve(n, nodes)
	for r in ans:
		print(r)

def __starting_point():
	main()
__starting_point()


n = int(input())
l = [list(map(int, input().split())) for i in range(n - 1)]
r = [[] for i in range(n + 1)]
ans = [-1 for i in range(n + 1)]
for i in l:
	(u, v, w) = i
	r[u].append((v, w))
	r[v].append((u, w))
q = [1]
ans[1] = 0
while len(q) > 0:
	t = q.pop()
	for i in r[t]:
		(V, W) = i
		if ans[V] != -1:
			continue
		q.append(V)
		c = ans[t]
		if W % 2 == 0:
			ans[V] = c
		else:
			ans[V] = c ^ 1
for i in ans[1:]:
	print(i)


n = int(input())
l = [[] for i in range(n)]
ans = [-1 for i in range(n)]
for i in range(n - 1):
	(u, v, w) = [int(x) for x in input().rstrip().split()]
	l[u - 1].append([v - 1, w])
	l[v - 1].append([u - 1, w])

def bfs():
	ans[0] = 0
	que = [0]
	while que:
		now = que.pop(0)
		for (i, j) in l[now]:
			if ans[i] == -1:
				if j % 2 == 0:
					ans[i] = ans[now]
				else:
					ans[i] = (ans[now] + 1) % 2
				que.append(i)
bfs()
for i in ans:
	print(i)


from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
ad_ls = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b, w) = map(int, input().split())
	ad_ls[a - 1].append([b - 1, w])
	ad_ls[b - 1].append([a - 1, w])
cost_ls = [0] * n
done_ls = [0] * n

def dfs(v, c):
	for (new, cost) in ad_ls[v]:
		if not done_ls[new]:
			cost_ls[new] = c + cost
			done_ls[new] = 1
			dfs(new, c + cost)
dfs(0, 0)
color_ls = [0] * n
for i in range(n):
	color_ls[i] = cost_ls[i] % 2
for color in color_ls:
	print(color)


from typing import List, Tuple

def main():
	(N, *X) = list(map(int, open(0).read().split()))
	tree: List[List[Tuple[int, int]]] = [[] for _ in range(N + 1)]
	for (u, v, w) in zip(*[iter(X)] * 3):
		w %= 2
		(tree[u].append((v, w)), tree[v].append((u, w)))
	color = [-1] * (N + 1)
	color[1] = 1
	stack = [1]
	while stack:
		u = stack.pop()
		cur = color[u]
		for (v, w) in tree[u]:
			if color[v] != -1:
				continue
			color[v] = cur ^ w
			stack.append(v)
	print('\n'.join(map(str, color[1:])))

def __starting_point():
	main()
__starting_point()


from collections import deque
n = int(input())
tree = {i: set() for i in range(n)}
cost = {}
for _ in range(n - 1):
	(u, v, w) = [int(x) - 1 for x in input().split()]
	tree[u].add(v)
	tree[v].add(u)
	cost[u, v] = w + 1
color = [-1] * n
color[0] = 0
que = deque([0])
while que:
	now = que.popleft()
	for i in tree[now]:
		if color[i] != -1:
			continue
		if cost[min(now, i), max(now, i)] % 2 == 0:
			color[i] = color[now]
		else:
			color[i] = color[now] ^ 1
		que.append(i)
print('\n'.join(map(str, color)))


n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	tree[u - 1].append((v - 1, w))
	tree[v - 1].append((u - 1, w))
stack = [0]
color = [-1] * n
color[0] = 0
while stack:
	v = stack.pop()
	for (child, w) in tree[v]:
		if color[child] < 0:
			color[child] = (color[v] + w) % 2
			stack.append(child)
for i in color:
	print(i)


import queue
N = int(input())
t = [[] for i in range(N)]
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	(u, v, w) = (u - 1, v - 1, w % 2)
	t[u].append([v, w])
	t[v].append([u, w])
q = queue.Queue()
ans = [-1 for i in range(N)]
ans[0] = 0
q.put(0)
while not q.empty():
	v = q.get()
	for vuw in t[v]:
		u = vuw[0]
		w = vuw[1]
		if ans[u] != -1:
			continue
		else:
			ans[u] = (ans[v] + w) % 2
			q.put(u)
for a in ans:
	print(a)


import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
E = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	E[u].append((v, w))
	E[v].append((u, w))
color = [-1] * (n + 1)

def dfs(i, j):
	color[i] = j
	for (w, l) in E[i]:
		if color[w] == -1:
			tj = j
			if l % 2 != 0:
				tj = int(not tj)
			dfs(w, tj)
dfs(1, 0)
[print(color[i]) for i in range(1, n + 1)]


import sys
readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, readline().split())
	G[u - 1].append((v - 1, w))
	G[v - 1].append((u - 1, w))
color = [-1] * N
stack = []
stack.append([0, -1, 0])
while stack:
	(v, parent, cost) = stack.pop()
	color[v] = cost
	for child in G[v]:
		if child[0] == parent:
			continue
		stack.append([child[0], v, (cost + child[1]) % 2])
for c in color:
	print(c)


N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
	(U, V, W) = map(int, input().split())
	edge[U - 1].append([V - 1, W])
	edge[V - 1].append([U - 1, W])
dist = [-1] * N
dist[0] = 0
q = [0]
while q:
	temp = q.pop()
	for (u, v) in edge[temp]:
		if dist[u] != -1:
			continue
		dist[u] = dist[temp] + v
		q.append(u)
for ans in dist:
	if ans % 2 == 0:
		print(1)
	else:
		print(0)


N = int(input())
from collections import deque
tree = [{} for _ in range(N)]
color = [-1] * N
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	tree[u - 1][v - 1] = w
	tree[v - 1][u - 1] = w
queue = deque()
queue.append((0, 0))
while queue:
	(v, w) = queue.pop()
	color[v] = w % 2
	for i in tree[v].keys():
		if color[i] == -1:
			queue.append((i, w + tree[v][i]))
for c in color:
	print(c)


from copy import copy
N = int(input())
G = [[] for _ in range(N)]
di = [-1] * N
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	G[u - 1].append([v - 1, w])
	G[v - 1].append([u - 1, w])
di[0] = 0
for i in range(1, N):
	if di[i] != -1:
		continue
	seen = [0] * N
	stack = [[0, 0]]
	while stack:
		(y, d) = stack.pop()
		if seen[y] == 1:
			continue
		seen[y] = 1
		for (z, dist) in G[y]:
			if seen[z] == 0:
				di[z] = d + dist
				stack.append([z, d + dist])
for i in range(N):
	if di[i] % 2 == 0:
		print(0)
	else:
		print(1)


((n,), *t) = [map(int, t.split()) for t in open(0)]
(*e,) = eval('[],' * -~n)
q = [(1, 0)]
f = [-1] * n
for (v, w, c) in t:
	e[v] += ((w, c),)
	e[w] += ((v, c),)
for (v, c) in q:
	f[v - 1] = c & 1
	for (w, d) in e[v]:
		q += [(w, c + d)] * (f[w - 1] < 0)
print(*f)


n = int(input())
X = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	X[u - 1].append([v - 1, w])
	X[v - 1].append([u - 1, w])
C = [-1] * n
q = [[0, 0]]
while q:
	(v, w) = q.pop()
	if w % 2 == 0:
		C[v] = 0
	else:
		C[v] = 1
	for (pv, pw) in X[v]:
		if C[pv] == -1:
			q.append([pv, pw + w])
for c in C:
	print(c)


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
L = [-1 for i in range(N)]
flg = [0 for i in range(N)]
M = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	M[u - 1].append([v - 1, w % 2])
	M[v - 1].append([u - 1, w % 2])
L[0] = 0

def dist(m, d):
	L[m] = d % 2
	for i in M[m]:
		if L[i[0]] == -1:
			dist(i[0], i[1] + d)
dist(0, 0)
for i in range(N):
	print(L[i])


import sys
sys.setrecursionlimit(20000000)
n = int(input())
g = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	g[u].append([v, w])
	g[v].append([u, w])
ans = [-1] * n

def dfs(x, y):
	for (i, j) in g[x]:
		if ans[i] == -1:
			ans[i] = (y + j) % 2
			dfs(i, y + j)
dfs(0, 0)
for i in ans:
	print(i)


n = int(input())
links = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	links[u].append((v, w))
	links[v].append((u, w))
ans = [-1] * (n + 1)
q = [(1, 0, 0)]
while q:
	(v, d, p) = q.pop()
	ans[v] = d
	for (u, w) in links[v]:
		if u == p:
			continue
		q.append((u, d + w, v))
print('\n'.join(map(lambda x: str(x % 2), ans[1:])))


from collections import deque
n = int(input())
uvw = [list(map(int, input().split())) for _ in range(n - 1)]
l = [[] for _ in range(n)]
for (u, v, w) in uvw:
	(u, v) = (u - 1, v - 1)
	l[u].append((v, w))
	l[v].append((u, w))
ans = [0] * n
parents = [-1] * n
q = deque([0])
while q:
	a = q.pop()
	for (i, j) in l[a]:
		if i == parents[a]:
			continue
		parents[i] = a
		q.append(i)
		ans[i] = ans[a] if j % 2 == 0 else (ans[a] + 1) % 2
for i in ans:
	print(i)


N = int(input())
uvw = [list(map(int, input().split())) for _ in [0] * (N - 1)]
connect = [[] for _ in [0] * N]
for (u, v, w) in uvw:
	connect[u - 1].append((v - 1, w))
	connect[v - 1].append((u - 1, w))
MAX = 10 ** 16
dist = [MAX] * N
dist[0] = 0
q = [0]
while q:
	i = q.pop()
	for (j, w) in connect[i]:
		if dist[j] == MAX:
			dist[j] = dist[i] + w
			q.append(j)
for o in dist:
	print(o % 2)


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
d = [[] for _ in range(N)]
iro = [0] * N

def dfs(n, v, k):
	for i in d[n]:
		if k % 2 != 0:
			iro[n] = 1
		if v == i[0]:
			continue
		dfs(i[0], n, k + i[1])
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	v -= 1
	u -= 1
	d[u].append((v, w))
	d[v].append((u, w))
dfs(0, 0, 0)
for i in iro:
	print(i)


import sys
sys.setrecursionlimit(1 << 30)
N = int(input())

def dfs(x):
	for y in Tree[x]:
		if Parent[x] != y:
			Parent[y] = x
			distance[y] += Web[min(x, y), max(x, y)] + distance[x]
			dfs(y)
Tree = [[] for i in range(N + 1)]
Parent = [0] * (N + 1)
Web = dict()
for i in range(N - 1):
	(a, b, w) = map(int, input().split())
	Tree[a].append(b)
	Tree[b].append(a)
	Web[min(a, b), max(a, b)] = w
distance = [0] * (N + 1)
dfs(1)
for i in distance[1:]:
	if i % 2 == 0:
		print(1)
	else:
		print(0)


def f(G, not_searched, results={0: '0'}):
	stack = []
	while len(not_searched) > 0:
		if len(stack) > 0:
			i = stack.pop()
			not_searched.remove(i)
		else:
			i = not_searched.pop()
		for (key, val) in G[i].items():
			if not key in not_searched:
				continue
			if val % 2 == 1:
				if results[i] == '0':
					results[key] = '1'
				else:
					results[key] = '0'
			else:
				results[key] = results[i]
			stack.append(key)
	return results
N = int(input())
G = [{} for _ in range(N)]
not_searched = set([i for i in range(N)])
if N == 1:
	print(results[0])
else:
	for i in range(N - 1):
		(u, v, w) = map(int, input().split())
		G[u - 1][v - 1] = w
		G[v - 1][u - 1] = w
	results = f(G, not_searched)
	for i in range(N):
		print(results[i])


N = int(input())
Tree = [[] for _ in range(N + 1)]
UVW = []
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	Tree[u].append(v)
	Tree[v].append(u)
	UVW.append((u, v, w))
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	x = stack.pop()
	order.append(x)
	for y in Tree[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)
dis = [0] * (N + 1)
for (u, v, w) in UVW:
	if parent[u] == v:
		dis[u] = w
	else:
		dis[v] = w
color = [-1] * (N + 1)
color[root] = 0
for x in order:
	for y in Tree[x]:
		if y == parent[x]:
			continue
		if dis[y] % 2 == 0:
			color[y] = color[x]
		else:
			color[y] = color[x] ^ 1
for i in range(1, N + 1):
	print(color[i])


import sys
sys.setrecursionlimit(20000000)
N = int(input())
Tree = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	Tree[u - 1].append([v - 1, w])
	Tree[v - 1].append([u - 1, w])
ans = [-1] * N

def dfs(node, dist):
	for (next_node, size) in Tree[node]:
		if ans[next_node] == -1:
			ans[next_node] = (dist + size) % 2
			dfs(next_node, dist + size)
dfs(0, 0)
print(*ans, sep='\n')


from collections import deque
n = int(input())
d = [0] * (n + 1)
tree = [[] for _ in range(n + 1)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	tree[u].append([v, w])
	tree[v].append([u, w])
q = deque([1])
done = [0] * (n + 1)
done[1] = 1
while q:
	now = q.popleft()
	for l in tree[now]:
		if not done[l[0]]:
			q.append(l[0])
			done[l[0]] = 1
			d[l[0]] = d[now] + l[1]
for i in range(1, n + 1):
	print(d[i] % 2)


from collections import defaultdict
N = int(input())
edges = defaultdict(list)
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	edges[u].append((v, w))
	edges[v].append((u, w))
colors = [None] * N
stack = [(0, 0)]
while stack:
	(u, c) = stack.pop()
	if colors[u] != None:
		continue
	colors[u] = c
	for (v, w) in edges[u]:
		stack.append((v, (c + w) % 2))
for u in range(N):
	print(colors[u])


n = int(input())
L = [[] for i in range(n + 1)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	L[u].append((v, w % 2))
	L[v].append((u, w % 2))
V = [0 for i in range(n + 1)]
V[1] = 1
ans = [0 for i in range(n + 1)]
que = [1]
head = 0
while len(que) > head:
	now = que[head]
	head += 1
	for nex in L[now]:
		if V[nex[0]] == 0:
			V[nex[0]] = 1
			ans[nex[0]] = ans[now] ^ nex[1]
			que.append(nex[0])
for pri in ans[1:]:
	print(pri)


import sys
sys.setrecursionlimit(10 ** 5)
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	edge[u].append((v, w))
	edge[v].append((u, w))

def dfs(u, v):
	for (e, w) in edge[u]:
		if e != v:
			ans[e] = (w + ans[u]) % 2
			dfs(e, u)
ans = [0] + [-1] * (N - 1)
dfs(0, -1)
print(*ans)


import sys

def input():
	return sys.stdin.readline().rstrip()

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
from collections import deque

def main():
	n = ii()
	edge = [[] for _ in range(n)]
	for i in range(n - 1):
		(u, v, w) = mi()
		u -= 1
		v -= 1
		edge[u].append((v, w))
		edge[v].append((u, w))
	dist = [0] * n
	parent = [-1] * n
	que = deque([0])
	while que:
		v = que.pop()
		for (nv, nx) in edge[v]:
			if parent[v] == nv:
				continue
			parent[nv] = v
			dist[nv] = dist[v] + nx % 2
			dist[nv] %= 2
			que.append(nv)
	print(*dist, sep='\n')

def __starting_point():
	main()
__starting_point()


from collections import deque
N = int(input())
table = [[] for i in range(N)]
for i in range(N - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	table[u].append((v, w))
	table[v].append((u, w))
dist = [-1] * N
dist[0] = 0
H = deque()
H.append(0)
while H:
	u = H.popleft()
	for (v, w) in table[u]:
		if dist[v] == -1:
			dist[v] = dist[u] if w % 2 == 0 else 1 - dist[u]
			H.append(v)
for i in range(N):
	print(dist[i])


import sys
sys.setrecursionlimit(500 * 500)
n = int(input())
nodes = [list(map(int, input().split())) for _ in range(n - 1)]
a = [[] for _ in range(n + 1)]
for node in nodes:
	a[node[0]].append([node[1], node[2]])
	a[node[1]].append([node[0], node[2]])
depth = [-1] * (n + 1)
depth[1] = 0

def dfs(a, s):
	for v in a[s]:
		if depth[v[0]] == -1:
			depth[v[0]] = depth[s] + v[1]
			dfs(a, v[0])
dfs(a, 1)
for d in depth[1:]:
	if d % 2 == 0:
		print(0)
	else:
		print(1)


from collections import deque
n = int(input())
ans = [-1] * n
ans[0] = 0
d = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	d[u - 1].append([v - 1, w])
	d[v - 1].append([u - 1, w])
cnt = 0
queue = deque()
queue.append(0)
while queue:
	u = queue.pop()
	for (v, w) in d[u]:
		if ans[v] == -1:
			if w % 2 == 0:
				ans[v] = ans[u]
			else:
				ans[v] = ans[u] ^ 1
			queue.append(v)
for i in range(n):
	print(ans[i])


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
n = int(input())
G = [[] for i in range(n)]
for i in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	G[u].append([v, w])
	G[v].append([u, w])
A = [0] * n

def dfs(s, p=-1):
	for g in G[s]:
		if g[0] != p:
			A[g[0]] = A[s] + g[1]
			dfs(g[0], s)
dfs(0)
for a in A:
	if a % 2 == 0:
		print(0)
	else:
		print(1)


import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
col = [0] * n
next = [[] for i in range(n)]
d = [float('INF')] * n
d[0] = 0

def dfs(now, parent):
	for (next1, w1) in next[now]:
		if next1 == parent:
			continue
		elif d[next1] == float('INF'):
			d[next1] = d[now] + w1
			dfs(next1, now)
for i in range(n - 1):
	(u, v, w) = list(map(int, input().split()))
	next[u - 1].append((v - 1, w))
	next[v - 1].append((u - 1, w))
dfs(0, -1)
for i in range(n):
	if d[i] % 2 == 0:
		print('0')
	else:
		print('1')


n = int(input())
links = [set() for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = map(int, input().split())
	u -= 1
	v -= 1
	w %= 2
	links[v].add((u, w))
	links[u].add((v, w))
colors = [-1] * n
q = [(0, 0, -1)]
while q:
	(v, c, p) = q.pop()
	colors[v] = c
	for (u, w) in links[v]:
		if u == p:
			continue
		q.append((u, c ^ w, v))
print('\n'.join(map(str, colors)))


from collections import deque
N = int(input())
graph = [[] for _ in range(N)]
dist = [-1] * N
for _ in range(N - 1):
	(u, v, w) = map(int, input().split())
	graph[u - 1].append((v - 1, w))
	graph[v - 1].append((u - 1, w))
q = deque()
dist[0] = 0
q.append(0)
while len(q) != 0:
	v = q.popleft()
	for (next_v, next_w) in graph[v]:
		if dist[next_v] != -1:
			continue
		dist[next_v] = dist[v] + next_w
		q.append(next_v)
for d in dist:
	if d % 2 == 0:
		print(0)
	else:
		print(1)


import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
color = [-1] * n
neighbor = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v, w) = tuple(map(int, input().split()))
	neighbor[u - 1].append((v - 1, w))
	neighbor[v - 1].append((u - 1, w))

def col(u, c):
	color[u] = c
	for (v, w) in neighbor[u]:
		if color[v] < 0:
			col(v, (c + w) % 2)
col(0, 0)
for i in range(n):
	print(color[i])