n = int(input())

ikeru = [[] for _ in range(n)]
for i in range(n-1):
	a, b, c = map(int, input().split())
	ikeru[a-1].append((b-1, c))
	ikeru[b-1].append((a-1, c))

#fukasa = [0 for _ in range(n)]
#fukasamoto = [0 for _ in range(n)]
kaisuu = 0
settansaku = set([])
setmada = {0}
kouho = 1
guuki = [0 for _ in range(n)]

while kouho != 0:
	kaisuu += 1
	for i in list(setmada):
		settansaku.add(i)
		setmada.remove(i)
		kouho -= 1
		for k, leng in ikeru[i]:
			if not k in setmada:
				if not k in settansaku:
					setmada.add(k)
					guuki[k] = (guuki[i] + leng) % 2
					kouho += 1
					#fukasa[k] = kaisuu
					#fukasamoto[k] = i+1

print("\n".join([str(guuki[i]) for i in range(n)])) n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] ikeru = [[] for _ in range(n)] ikeru [[] for _ in range(n)] for i in range(n-1):
	a, b, c = map(int, input().split())
	ikeru[a-1].append((b-1, c))
	ikeru[b-1].append((a-1, c))

#fukasa = [0 for _ in range(n)]
#fukasamoto = [0 for _ in range(n)] i range(n-1) range n-1 n 1 a, b, c = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b c ikeru[a-1].append((b-1, c)) [a-1].append [a-1] ikeru a-1 a 1 append (b-1, c) b-1 b 1 c ikeru[b-1].append((a-1, c)) [b-1].append [b-1] ikeru b-1 b 1 append (a-1, c) a-1 a 1 c kaisuu = 0 kaisuu 0 settansaku = set([]) settansaku set([]) set [] setmada = {0} setmada {0} kouho = 1 kouho 1 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 guuki = [0 for _ in range(n)] guuki [0 for _ in range(n)] while kouho != 0:
	kaisuu += 1
	for i in list(setmada):
		settansaku.add(i)
		setmada.remove(i)
		kouho -= 1
		for k, leng in ikeru[i]:
			if not k in setmada:
				if not k in settansaku:
					setmada.add(k)
					guuki[k] = (guuki[i] + leng) % 2
					kouho += 1
					#fukasa[k] = kaisuu
					#fukasamoto[k] = i+1 kouho != 0 kouho 0 kaisuu += 1 kaisuu 1 for i in list(setmada):
		settansaku.add(i)
		setmada.remove(i)
		kouho -= 1
		for k, leng in ikeru[i]:
			if not k in setmada:
				if not k in settansaku:
					setmada.add(k)
					guuki[k] = (guuki[i] + leng) % 2
					kouho += 1
					#fukasa[k] = kaisuu
					#fukasamoto[k] = i+1 i list(setmada) list setmada settansaku.add(i) settansaku.add settansaku add i setmada.remove(i) setmada.remove setmada remove i kouho -= 1 kouho 1 for k, leng in ikeru[i]:
			if not k in setmada:
				if not k in settansaku:
					setmada.add(k)
					guuki[k] = (guuki[i] + leng) % 2
					kouho += 1
					#fukasa[k] = kaisuu
					#fukasamoto[k] = i+1 k leng ikeru[i] ikeru i if not k in setmada:
				if not k in settansaku:
					setmada.add(k)
					guuki[k] = (guuki[i] + leng) % 2
					kouho += 1
					#fukasa[k] = kaisuu
					#fukasamoto[k] = i+1 not k in setmada k in setmada k setmada if not k in settansaku:
					setmada.add(k)
					guuki[k] = (guuki[i] + leng) % 2
					kouho += 1
					#fukasa[k] = kaisuu
					#fukasamoto[k] = i+1 not k in settansaku k in settansaku k settansaku setmada.add(k) setmada.add setmada add k guuki[k] = (guuki[i] + leng) % 2 guuki[k] guuki k (guuki[i] + leng) % 2 guuki[i] + leng guuki[i] guuki i leng 2 kouho += 1 kouho 1 str(guuki[i]) for i in range(n) for i in range(n) i range(n) range n for i in range(n) str(guuki[i]) str guuki[i] guuki i print("\n".join([str(guuki[i]) for i in range(n)])) print "\n".join([str(guuki[i]) for i in range(n)]) "\n".join "\n" join [str(guuki[i]) for i in range(n)] c = map(int, input().split()) map(int, input().split()) c kaisuu = 0 0 kaisuu kaisuu += 1 1 kaisuu a, b, c = map(int, input().split()) map(int, input().split()) a kouho = 1 1 kouho kouho -= 1 1 kouho settansaku = set([]) set([]) settansaku b, c = map(int, input().split()) map(int, input().split()) b ikeru = [[] for _ in range(n)] [[] for _ in range(n)] ikeru n = int(input()) int(input()) n setmada = {0} {0} setmada guuki = [0 for _ in range(n)] [0 for _ in range(n)] guuki kouho += 1 1 kouho
n = int(input())

ikeru = [[] for _ in range(n)]
for i in range(n-1):
	a, b, c = map(int, input().split())
	ikeru[a-1].append((b-1, c))
	ikeru[b-1].append((a-1, c))

#fukasa = [0 for _ in range(n)]
#fukasamoto = [0 for _ in range(n)]
kaisuu = 0
settansaku = set([])
setmada = {0}
kouho = 1
guuki = [0 for _ in range(n)]

while kouho != 0:
	kaisuu += 1
	for i in list(setmada):
		settansaku.add(i)
		setmada.remove(i)
		kouho -= 1
		for k, leng in ikeru[i]:
			if not k in setmada:
				if not k in settansaku:
					setmada.add(k)
					guuki[k] = (guuki[i] + leng) % 2
					kouho += 1
					#fukasa[k] = kaisuu
					#fukasamoto[k] = i+1

print("\n".join([str(guuki[i]) for i in range(n)]))