import heapq

N = int(input())

UVW = [list(map(int,input().split())) for _ in [0]*(N-1)]



E = [{} for _ in [0]*N]

for u,v,c in UVW:

    E[u-1][v-1] = c

    E[v-1][u-1] = c



def Dijkstra(N,E,start):

    d = [-1]*N

    q = [(0,start)]

    while q:

        ci,i = heapq.heappop(q)

        if d[i]!= -1:continue

        d[i] = ci

        for j,cj in E[i].items():

            if d[j]!=-1:continue

            heapq.heappush(q,(ci+cj,j))

    return d



d = Dijkstra(N,E,0)

print(*[l%2 for l in d],sep="\n")

#DFS

N = int(input())

UVW = [list(map(int,input().split())) for _ in [0]*(N-1)]



E = [{} for _ in [0]*N]

for u,v,c in UVW:

    E[u-1][v-1] = c

    E[v-1][u-1] = c



def dist_dfs_tree(N,E,start):

    d = [-1]*N

    d[start] = 0

    q = [start]

    while q:

        i = q.pop()

        ci = d[i]

        for j,cj in E[i].items():

            if d[j] !=-1:continue

            d[j] = ci+cj

            q.append(j)

    return d



d = dist_dfs_tree(N,E,0)

print(*[l%2 for l in d],sep="\n")

import heapq

N = int(input())
UVW = [list(map(int, input().split())) for _ in [0] * (N - 1)]
E = [{} for _ in [0] * N]
for u, v, c in UVW:
    E[u - 1][v - 1] = c
    E[v - 1][u - 1] = c


def Dijkstra(N, E, start):
    d = [-1] * N
    q = [(0, start)]
    while q:
        ci, i = heapq.heappop(q)
        if d[i] != -1:
            continue
        d[i] = ci
        for j, cj in E[i].items():
            if d[j] != -1:
                continue
            heapq.heappush(q, (ci + cj, j))
    return d


d = Dijkstra(N, E, 0)
print(*[l % 2 for l in d], sep="\n")

# DFS
N = int(input())
UVW = [list(map(int, input().split())) for _ in [0] * (N - 1)]
E = [{} for _ in [0] * N]
for u, v, c in UVW:
    E[u - 1][v - 1] = c
    E[v - 1][u - 1] = c


def dist_dfs_tree(N, E, start):
    d = [-1] * N
    d[start] = 0
    q = [start]
    while q:
        i = q.pop()
        ci = d[i]
        for j, cj in E[i].items():
            if d[j] != -1:
                continue
            d[j] = ci + cj
            q.append(j)
    return d


d = dist_dfs_tree(N, E, 0)
print(*[l % 2 for l in d], sep="\n")

-import heapq - +# DFS -def Dijkstra(N, E, start): +def dist_dfs_tree(N, E, start): -    q = [(0, start)] +    d[start] = 0 +    q = [start] -        ci, i = heapq.heappop(q) -        if d[i] != -1: -            continue -        d[i] = ci +        i = q.pop() +        ci = d[i] -            heapq.heappush(q, (ci + cj, j)) +            d[j] = ci + cj +            q.append(j) -d = Dijkstra(N, E, 0) +d = dist_dfs_tree(N, E, 0)