import sys

input=sys.stdin.buffer.readline

sys.setrecursionlimit(10**9)

n=int(input())

edges=[[] for i in range(n)]

for i in range(n-1):

    a,s,w=map(int,input().split())

    edges[a-1].append([s-1,w]);edges[s-1].append([a-1,w])

colors=[-1]*n

colors[0]=1

def dfs(now):

    for to,cost in edges[now]:

        if colors[to]==-1:

            colors[to]=(cost+colors[now])%2

            dfs(to)



dfs(0)

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

import sys

input=sys.stdin.buffer.readline

sys.setrecursionlimit(10**9)



N = int(input())

# v = [list(map(int, input().split())) for _ in range(N-1)]



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



for i in range(N-1):

    v1, v2, w = map(int, input().split())

    edge[v1-1].append((v2-1, w))

    edge[v2-1].append((v1-1, w))



color = [-1 for _ in range(N)]

color[0] = 1



def dfs(x):

    for v, w in edge[x]:

        if color[v] == -1:

            color[v] = (w + color[x])%2

            dfs(v)







dfs(0)

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

import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
n = int(input())
edges = [[] for i in range(n)]
for i in range(n - 1):
    a, s, w = map(int, input().split())
    edges[a - 1].append([s - 1, w])
    edges[s - 1].append([a - 1, w])
colors = [-1] * n
colors[0] = 1


def dfs(now):
    for to, cost in edges[now]:
        if colors[to] == -1:
            colors[to] = (cost + colors[now]) % 2
            dfs(to)


dfs(0)
print(*colors, sep="\n")

import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
N = int(input())
# v = [list(map(int, input().split())) for _ in range(N-1)]
edge = [[] for _ in range(N)]
for i in range(N - 1):
    v1, v2, w = map(int, input().split())
    edge[v1 - 1].append((v2 - 1, w))
    edge[v2 - 1].append((v1 - 1, w))
color = [-1 for _ in range(N)]
color[0] = 1


def dfs(x):
    for v, w in edge[x]:
        if color[v] == -1:
            color[v] = (w + color[x]) % 2
            dfs(v)


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

-n = int(input()) -edges = [[] for i in range(n)] -for i in range(n - 1): -    a, s, w = map(int, input().split()) -    edges[a - 1].append([s - 1, w]) -    edges[s - 1].append([a - 1, w]) -colors = [-1] * n -colors[0] = 1 +N = int(input()) +# v = [list(map(int, input().split())) for _ in range(N-1)] +edge = [[] for _ in range(N)] +for i in range(N - 1): +    v1, v2, w = map(int, input().split()) +    edge[v1 - 1].append((v2 - 1, w)) +    edge[v2 - 1].append((v1 - 1, w)) +color = [-1 for _ in range(N)] +color[0] = 1 -def dfs(now): -    for to, cost in edges[now]: -        if colors[to] == -1: -            colors[to] = (cost + colors[now]) % 2 -            dfs(to) +def dfs(x): +    for v, w in edge[x]: +        if color[v] == -1: +            color[v] = (w + color[x]) % 2 +            dfs(v) -print(*colors, sep="\n") +print(*color, sep="\n")