import sys



sys.setrecursionlimit(100000)



# input data

n=int(eval(input()))

u=[]

v=[]

w=[]

for i in range(0,n-1):

	ui,vi,wi = list(map(int, input().split()))

	u.append(ui)

	v.append(vi)

	w.append(wi%2)





# solve

ans=[]

for i in range(0,n+1):

	ans.append(-1)



_neighbors=[]

for i in range(0,n+1):

	_neighbors.append([])



for i in range(0,n-1):

	_neighbors[u[i]].append([v[i], w[i]])

	_neighbors[v[i]].append([u[i], w[i]])



# paint v with c=0,1 and its neighbors

def bfs(u,c):

	if ans[u] != -1:

		return



	ans[u] = c



	for vw in _neighbors[u]:

		if vw[1] == 0:

			bfs(vw[0],c)

		else:

			bfs(vw[0],1-c)



bfs(1,0)



for i in range(1,n+1):

	print((ans[i]))

import sys

from collections import defaultdict

readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10**8)





def geta(fn=lambda s: s.decode()):

    return map(fn, readline().split())





def gete(fn=lambda s: s.decode()):

    return fn(readline().rstrip())





def main():

    N = gete(int)

    g = [set() for _ in range(N+1)]

    for _ in range(N-1):

        u, v, w = geta(int)

        g[u].add((v, w))

        g[v].add((u, w))



    dist = [-1] * (N+1)

    color = [-1]*(N+1)



    dist[1] = 0

    color[1] = 0



    def dfs(i, d):



        dist[i] = d

        color[i] = 0 if d & 1 == 0 else 1



        for j, wj in g[i]:

            if dist[j] < 0:

                dfs(j, d + wj)



    dfs(1, 0)



    print(*color[1:], sep="\n")





if __name__ == "__main__":

    main()

import sys

sys.setrecursionlimit(100000)
# input data
n = int(eval(input()))
u = []
v = []
w = []
for i in range(0, n - 1):
    ui, vi, wi = list(map(int, input().split()))
    u.append(ui)
    v.append(vi)
    w.append(wi % 2)
# solve
ans = []
for i in range(0, n + 1):
    ans.append(-1)
_neighbors = []
for i in range(0, n + 1):
    _neighbors.append([])
for i in range(0, n - 1):
    _neighbors[u[i]].append([v[i], w[i]])
    _neighbors[v[i]].append([u[i], w[i]])
# paint v with c=0,1 and its neighbors
def bfs(u, c):
    if ans[u] != -1:
        return
    ans[u] = c
    for vw in _neighbors[u]:
        if vw[1] == 0:
            bfs(vw[0], c)
        else:
            bfs(vw[0], 1 - c)


bfs(1, 0)
for i in range(1, n + 1):
    print((ans[i]))

import sys
from collections import defaultdict

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N = gete(int)
    g = [set() for _ in range(N + 1)]
    for _ in range(N - 1):
        u, v, w = geta(int)
        g[u].add((v, w))
        g[v].add((u, w))
    dist = [-1] * (N + 1)
    color = [-1] * (N + 1)
    dist[1] = 0
    color[1] = 0

    def dfs(i, d):
        dist[i] = d
        color[i] = 0 if d & 1 == 0 else 1
        for j, wj in g[i]:
            if dist[j] < 0:
                dfs(j, d + wj)

    dfs(1, 0)
    print(*color[1:], sep="\n")


if __name__ == "__main__":
    main()

+from collections import defaultdict -sys.setrecursionlimit(100000) -# input data -n = int(eval(input())) -u = [] -v = [] -w = [] -for i in range(0, n - 1): -    ui, vi, wi = list(map(int, input().split())) -    u.append(ui) -    v.append(vi) -    w.append(wi % 2) -# solve -ans = [] -for i in range(0, n + 1): -    ans.append(-1) -_neighbors = [] -for i in range(0, n + 1): -    _neighbors.append([]) -for i in range(0, n - 1): -    _neighbors[u[i]].append([v[i], w[i]]) -    _neighbors[v[i]].append([u[i], w[i]]) -# paint v with c=0,1 and its neighbors -def bfs(u, c): -    if ans[u] != -1: -        return -    ans[u] = c -    for vw in _neighbors[u]: -        if vw[1] == 0: -            bfs(vw[0], c) -        else: -            bfs(vw[0], 1 - c) +readline = sys.stdin.buffer.readline +sys.setrecursionlimit(10**8) -bfs(1, 0) -for i in range(1, n + 1): -    print((ans[i])) +def geta(fn=lambda s: s.decode()): +    return map(fn, readline().split()) + + +def gete(fn=lambda s: s.decode()): +    return fn(readline().rstrip()) + + +def main(): +    N = gete(int) +    g = [set() for _ in range(N + 1)] +    for _ in range(N - 1): +        u, v, w = geta(int) +        g[u].add((v, w)) +        g[v].add((u, w)) +    dist = [-1] * (N + 1) +    color = [-1] * (N + 1) +    dist[1] = 0 +    color[1] = 0 + +    def dfs(i, d): +        dist[i] = d +        color[i] = 0 if d & 1 == 0 else 1 +        for j, wj in g[i]: +            if dist[j] < 0: +                dfs(j, d + wj) + +    dfs(1, 0) +    print(*color[1:], sep="\n") + + +if __name__ == "__main__": +    main()