# coding: utf-8

from collections import deque



n = int(eval(input()))



lw = [[] for _ in range(n+1)]

for i in range(n-1):

    u,v,w = list(map(int,input().split()))

    lw[u].append((v,w))

    lw[v].append((u,w))



#print(lw)



ans = [-1] * (n+1)

q = deque()

ans[1] = 0

q.append(1)

while q:

    r = q.popleft()

    prev = ans[r]

    

    for x in lw[r]:

        #print(x)

        y = x[0]

        if ans[y] >= 0:

            continue

        q.append(y)

        if x[1]%2==0:

            ans[y] = ans[r]

        else:

            ans[y] = 1 - ans[r]



for x in ans[1:]:

    print(x)

# coding: utf-8

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

# coding: utf-8
from collections import deque

n = int(eval(input()))
lw = [[] for _ in range(n + 1)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    lw[u].append((v, w))
    lw[v].append((u, w))
# print(lw)
ans = [-1] * (n + 1)
q = deque()
ans[1] = 0
q.append(1)
while q:
    r = q.popleft()
    prev = ans[r]
    for x in lw[r]:
        # print(x)
        y = x[0]
        if ans[y] >= 0:
            continue
        q.append(y)
        if x[1] % 2 == 0:
            ans[y] = ans[r]
        else:
            ans[y] = 1 - ans[r]
for x in ans[1:]:
    print(x)

# coding: utf-8
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()

-from collections import deque +import sys +import copy -n = int(eval(input())) -lw = [[] for _ in range(n + 1)] -for i in range(n - 1): -    u, v, w = list(map(int, input().split())) -    lw[u].append((v, w)) -    lw[v].append((u, w)) -# print(lw) -ans = [-1] * (n + 1) -q = deque() -ans[1] = 0 -q.append(1) -while q: -    r = q.popleft() -    prev = ans[r] -    for x in lw[r]: -        # print(x) -        y = x[0] -        if ans[y] >= 0: +sys.setrecursionlimit(10**9) + + +def dfs(seen, graph, i): +    for v, w in graph[i]: +        if seen[v - 1] != -1: -        q.append(y) -        if x[1] % 2 == 0: -            ans[y] = ans[r] -        else: -            ans[y] = 1 - ans[r] -for x in ans[1:]: -    print(x) +        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()