Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
q = []
c = [0 for i in range(N)]
l = [0 for i in range(N)]
A = [[] for i in range(N)]
W = [[0 for i in range(N)] for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	u = u - 1
	v = v - 1
	
	A[u].append(v)
	A[v].append(u)
	W[u][v] = w
	W[v][u] = w

q.append(0)
while len(q):
	i = q.pop(0)
	c[i] = 1
	for j in A[i]:
		if c[j] == 0:
			q.append(j)
			l[j] = l[i] + W[i][j]

for i in l:
	print('{}'.format(i%2))

Fixed submission:
N = int(input())
q = []
c = [0 for i in range(N)]
l = [0 for i in range(N)]
A = [[] for i in range(N)]
W = [[] for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	u = u - 1
	v = v - 1
	
	A[u].append(v)
	A[v].append(u)
	W[u].append(w)
	W[v].append(w)

q.append(0)
while len(q):
	i = q.pop(0)
	c[i] = 1
	k = 0
	for j in A[i]:
		if c[j] == 0:
			q.append(j)
			l[j] = l[i] + W[i][k]
		k = k + 1

for i in l:
	print('{}'.format(i%2))

Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue

'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N = int(input())
q = Queue()
c = [0 for i in range(N)]
l = [0 for i in range(N)]
A = [[] for i in range(N)]
W = [[0 for i in range(N)] for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	u = u - 1
	v = v - 1
	
	A[u].append(v)
	A[v].append(u)
	W[u][v] = w
	W[v][u] = w

q.put(0)
while not q.empty():
	i = q.get()
	c[i] = 1
	for j in A[i]:
		if c[j] == 0:
			q.put(j)
			l[j] = l[i] + W[i][j]

for i in l:
	print('{}'.format(i%2))

Fixed submission:
N = int(input())
q = []
c = [0 for i in range(N)]
l = [0 for i in range(N)]
A = [[] for i in range(N)]
W = [[] for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	u = u - 1
	v = v - 1
	
	A[u].append(v)
	A[v].append(u)
	W[u].append(w)
	W[v].append(w)

q.append(0)
while len(q):
	i = q.pop(0)
	c[i] = 1
	k = 0
	for j in A[i]:
		if c[j] == 0:
			q.append(j)
			l[j] = l[i] + W[i][k]
		k = k + 1

for i in l:
	print('{}'.format(i%2))

Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue

'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N = int(input())
q = Queue()
c = [0 for i in range(N)]
l = [0 for i in range(N)]

u, v, w = map(int,input().split())
c[u-1] = 1
l[u-1] = 0
c[v-1] = 1
l[v-1] = w
		
for i in range(1,N-1):
	u, v, w = map(int,input().split())
	u = u - 1
	v = v - 1
	if c[u] == 0 and c[v] == 0:
		q.put([u,v,w])
	elif c[u] == 0 and c[v] == 1:
		c[u] = 1
		l[u] = l[v] + w
	elif c[u] == 1 and c[v] == 0:
		c[v] = 1
		l[v] = l[u] + w

while not q.empty():
	u, v, w = q.get()
	if c[u] == 0 and c[v] == 0:
		q.put([u,v,w])
	elif c[u] == 0 and c[v] == 1:
		c[u] = 1
		l[u] = l[v] + w
	elif c[u] == 1 and c[v] == 0:
		c[v] = 1
		l[v] = l[u] + w

for i in l:
	print('{}'.format(i%2))

Fixed submission:
N = int(input())
q = []
c = [0 for i in range(N)]
l = [0 for i in range(N)]
A = [[] for i in range(N)]
W = [[] for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	u = u - 1
	v = v - 1
	
	A[u].append(v)
	A[v].append(u)
	W[u].append(w)
	W[v].append(w)

q.append(0)
while len(q):
	i = q.pop(0)
	c[i] = 1
	k = 0
	for j in A[i]:
		if c[j] == 0:
			q.append(j)
			l[j] = l[i] + W[i][k]
		k = k + 1

for i in l:
	print('{}'.format(i%2))

Buggy python submission (verdict: Time Limit Exceeded):
from queue import LifoQueue

'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N = int(input())
A =  [[0 for i in range(N)] for j in range(N)]
q = LifoQueue()
#b = [-1 for i in range(N)]
c = [0 for i in range(N)]
l = [0 for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	A[u-1][v-1] = w
	A[v-1][u-1] = w

q.put(0)
while not q.empty():
	i = q.get()
	c[i] = 1
	for j in range(N):
		if A[i][j] > 0 and c[j] == 0:
			q.put(j)
			#b[j] = i
			l[j] = l[i] + A[i][j]

for i in l:
	print('{}'.format(i%2))


Fixed submission:
N = int(input())
q = []
c = [0 for i in range(N)]
l = [0 for i in range(N)]
A = [[] for i in range(N)]
W = [[] for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	u = u - 1
	v = v - 1
	
	A[u].append(v)
	A[v].append(u)
	W[u].append(w)
	W[v].append(w)

q.append(0)
while len(q):
	i = q.pop(0)
	c[i] = 1
	k = 0
	for j in A[i]:
		if c[j] == 0:
			q.append(j)
			l[j] = l[i] + W[i][k]
		k = k + 1

for i in l:
	print('{}'.format(i%2))

Buggy python submission (verdict: Time Limit Exceeded):
from queue import LifoQueue

'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N = int(input())
A =  [[0 for i in range(N)] for j in range(N)]
q = LifoQueue()
b = [-1 for i in range(N)]
c = [0 for i in range(N)]
l = [0 for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	A[u-1][v-1] = w
	A[v-1][u-1] = w

q.put(0)
while not q.empty():
	i = q.get()
	c[i] = 1
	for j in range(N):
		if A[i][j] > 0 and c[j] == 0:
			q.put(j)
			b[j] = i
			l[j] = l[i] + A[i][j]

for i in l:
	print('{}'.format(i%2))


Fixed submission:
N = int(input())
q = []
c = [0 for i in range(N)]
l = [0 for i in range(N)]
A = [[] for i in range(N)]
W = [[] for i in range(N)]

for i in range(N-1):
	u, v, w = map(int,input().split())
	u = u - 1
	v = v - 1
	
	A[u].append(v)
	A[v].append(u)
	W[u].append(w)
	W[v].append(w)

q.append(0)
while len(q):
	i = q.pop(0)
	c[i] = 1
	k = 0
	for j in A[i]:
		if c[j] == 0:
			q.append(j)
			l[j] = l[i] + W[i][k]
		k = k + 1

for i in l:
	print('{}'.format(i%2))