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].append((b-1,c%2))

		con[b-1].append((a-1,c%2))

 

	que=deque([0])

	while que:

		cur=que.popleft()

		for nxt,d in con[cur]:

			if dist[nxt]==None:

				que.append(nxt)

				dist[nxt]=(dist[cur]+d)%2



	print(*dist,sep="\n")



if __name__=="__main__":

	solve()

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].append((b-1,c%2))

		con[b-1].append((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")



if __name__=="__main__":

	solve()

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].append((b - 1, c % 2))
        con[b - 1].append((a - 1, c % 2))
    que = deque([0])
    while que:
        cur = que.popleft()
        for nxt, d in con[cur]:
            if dist[nxt] == None:
                que.append(nxt)
                dist[nxt] = (dist[cur] + d) % 2
    print(*dist, sep="\n")


if __name__ == "__main__":
    solve()

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].append((b - 1, c % 2))
        con[b - 1].append((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")


if __name__ == "__main__":
    solve()

-    que = deque([0]) -    while que: -        cur = que.popleft() +    stk = deque([0]) +    while stk: +        cur = stk.pop() -                que.append(nxt) +                stk.append(nxt)