import collections

N = int(input())

UVW = [[int(x) for x in input().split()] for _ in range(N - 1)]


ans = [-1] * N

A = [[] for _ in range(N)]


for u, v, w in UVW:
    A[u - 1].append([v - 1, w % 2])
    A[v - 1].append([u - 1, w % 2])

q = collections.deque()
q.append(0)

ans[0] = 0
while q:
    c = q.popleft()

    for ni, nd in A[c]:
        if ans[ni] != -1:
            continue

        if nd == 0:
            ans[ni] = ans[c]
        else:
            ans[ni] = ans[c] ^ 1

        q.append(ni)

if sum(ans) == 0:
    ans[0] = 1

for a in ans:
    print(a)


 import collections collections N = int(input()) N int(input()) int input() input [int(x) for x in input().split()] for _ in range(N - 1) for _ in range(N - 1) _ range(N - 1) range N - 1 N 1 for _ in range(N - 1) [int(x) for x in input().split()] UVW = [[int(x) for x in input().split()] for _ in range(N - 1)] UVW [[int(x) for x in input().split()] for _ in range(N - 1)] ans = [-1] * N ans [-1] * N [-1] -1 N [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] A = [[] for _ in range(N)] A [[] for _ in range(N)] for u, v, w in UVW:
    A[u - 1].append([v - 1, w % 2])
    A[v - 1].append([u - 1, w % 2]) u v w UVW A[u - 1].append([v - 1, w % 2]) [u - 1].append [u - 1] A u - 1 u 1 append [v - 1, w % 2] v - 1 v 1 w % 2 w 2 A[v - 1].append([u - 1, w % 2]) [v - 1].append [v - 1] A v - 1 v 1 append [u - 1, w % 2] u - 1 u 1 w % 2 w 2 q = collections.deque() q collections.deque() collections.deque collections deque q.append(0) q.append q append 0 ans[0] = 0 ans[0] ans 0 0 while q:
    c = q.popleft()

    for ni, nd in A[c]:
        if ans[ni] != -1:
            continue

        if nd == 0:
            ans[ni] = ans[c]
        else:
            ans[ni] = ans[c] ^ 1

        q.append(ni) q c = q.popleft() c q.popleft() q.popleft q popleft for ni, nd in A[c]:
        if ans[ni] != -1:
            continue

        if nd == 0:
            ans[ni] = ans[c]
        else:
            ans[ni] = ans[c] ^ 1

        q.append(ni) ni nd A[c] A c if ans[ni] != -1:
            continue

         ans[ni] != -1 ans[ni] ans ni -1 continue if nd == 0:
            ans[ni] = ans[c]
        else:
            ans[ni] = ans[c] ^ 1

         nd == 0 nd 0 ans[ni] = ans[c] ans[ni] ans ni ans[c] ans c ans[ni] = ans[c] ^ 1 ans[ni] ans ni ans[c] ^ 1 ans[c] ans c 1 q.append(ni) q.append q append ni if sum(ans) == 0:
    ans[0] = 1 sum(ans) == 0 sum(ans) sum ans 0 ans[0] = 1 ans[0] ans 0 1 for a in ans:
    print(a) a ans print(a) print a N = int(input()) int(input()) N UVW = [[int(x) for x in input().split()] for _ in range(N - 1)] [[int(x) for x in input().split()] for _ in range(N - 1)] UVW ans = [-1] * N [-1] * N ans A = [[] for _ in range(N)] [[] for _ in range(N)] A q = collections.deque() collections.deque() q c = q.popleft() q.popleft() c
import collections

N = int(input())

UVW = [[int(x) for x in input().split()] for _ in range(N - 1)]


ans = [-1] * N

A = [[] for _ in range(N)]


for u, v, w in UVW:
    A[u - 1].append([v - 1, w % 2])
    A[v - 1].append([u - 1, w % 2])

q = collections.deque()
q.append(0)

ans[0] = 0
while q:
    c = q.popleft()

    for ni, nd in A[c]:
        if ans[ni] != -1:
            continue

        if nd == 0:
            ans[ni] = ans[c]
        else:
            ans[ni] = ans[c] ^ 1

        q.append(ni)

if sum(ans) == 0:
    ans[0] = 1

for a in ans:
    print(a)



