import sys

sys.setrecursionlimit(10 ** 9)



N = int(input())

T = [[] for i in range(N)]

for i in range(N - 1):

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

    u, v = u - 1, v - 1

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

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





visited = [False] * N

visited[0] = True





def dfs(n):

    visited = [False] * N

    stack = [[n, 0]]

    longest = [-1, -1]



    while stack:

        node, weight = stack.pop()

        if visited[node]:

            continue

        visited[node] = True

        if longest[1] < weight:

            longest = [node, weight]



        for n, w in T[node]:

            if not visited[n]:

                stack.append([n, w + weight])



    return longest





start, xw = dfs(0)





color = [None] * N





def dfs(n):

    for to, weight in T[n]:

        if color[to] is None:

            if weight % 2 == 0:

                color[to] = color[n]

                dfs(to)

            else:

                color[to] = color[n] ^ 1

                dfs(to)





color[start] = 0

dfs(start)

print(*color, sep='\n')

N = int(input())

T = [[] for i in range(N)]

for i in range(N - 1):

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

    u, v = u - 1, v - 1

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

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





color = [-1] * N

stack = [[0, 0]]

while stack:

    n, w = stack.pop()

    color[n] = w % 2



    for to, to_w in T[n]:

        if color[to] >= 0:

            continue



        stack.append([to, w + to_w])



print(*color, sep='\n')

import sys

sys.setrecursionlimit(10**9)
N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    u, v = u - 1, v - 1
    T[u].append([v, w])
    T[v].append([u, w])
visited = [False] * N
visited[0] = True


def dfs(n):
    visited = [False] * N
    stack = [[n, 0]]
    longest = [-1, -1]
    while stack:
        node, weight = stack.pop()
        if visited[node]:
            continue
        visited[node] = True
        if longest[1] < weight:
            longest = [node, weight]
        for n, w in T[node]:
            if not visited[n]:
                stack.append([n, w + weight])
    return longest


start, xw = dfs(0)
color = [None] * N


def dfs(n):
    for to, weight in T[n]:
        if color[to] is None:
            if weight % 2 == 0:
                color[to] = color[n]
                dfs(to)
            else:
                color[to] = color[n] ^ 1
                dfs(to)


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

N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    u, v = u - 1, v - 1
    T[u].append([v, w])
    T[v].append([u, w])
color = [-1] * N
stack = [[0, 0]]
while stack:
    n, w = stack.pop()
    color[n] = w % 2
    for to, to_w in T[n]:
        if color[to] >= 0:
            continue
        stack.append([to, w + to_w])
print(*color, sep="\n")

-import sys - -sys.setrecursionlimit(10**9) -visited = [False] * N -visited[0] = True - - -def dfs(n): -    visited = [False] * N -    stack = [[n, 0]] -    longest = [-1, -1] -    while stack: -        node, weight = stack.pop() -        if visited[node]: +color = [-1] * N +stack = [[0, 0]] +while stack: +    n, w = stack.pop() +    color[n] = w % 2 +    for to, to_w in T[n]: +        if color[to] >= 0: -        visited[node] = True -        if longest[1] < weight: -            longest = [node, weight] -        for n, w in T[node]: -            if not visited[n]: -                stack.append([n, w + weight]) -    return longest - - -start, xw = dfs(0) -color = [None] * N - - -def dfs(n): -    for to, weight in T[n]: -        if color[to] is None: -            if weight % 2 == 0: -                color[to] = color[n] -                dfs(to) -            else: -                color[to] = color[n] ^ 1 -                dfs(to) - - -color[start] = 0 -dfs(start) +        stack.append([to, w + to_w])