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

n=int(input())

col=[-1]*n

e=[[[],[]]for i in range(n)]

for i in range(n-1):

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

    u-=1

    v-=1

    w%=2

    e[u][w].append(v)

    e[v][w].append(u)

col[0]=1

from collections import deque

dq=deque([])

#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)

dq.append(0)

while dq:

    a=dq.pop()

    b=col[a]

    for i in range(2):

        for ne in e[a][i]:

            if col[ne]==-1:

                col[ne]=b^i

                dq.appendleft(ne)

print(*col,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")

n = int(input())
col = [-1] * n
e = [[[], []] for i in range(n)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    w %= 2
    e[u][w].append(v)
    e[v][w].append(u)
col[0] = 1
from collections import deque

dq = deque([])
# pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
dq.append(0)
while dq:
    a = dq.pop()
    b = col[a]
    for i in range(2):
        for ne in e[a][i]:
            if col[ne] == -1:
                col[ne] = b ^ i
                dq.appendleft(ne)
print(*col, sep="\n")

-import sys +n = int(input()) +col = [-1] * n +e = [[[], []] for i in range(n)] +for i in range(n - 1): +    u, v, w = map(int, input().split()) +    u -= 1 +    v -= 1 +    w %= 2 +    e[u][w].append(v) +    e[v][w].append(u) +col[0] = 1 +from collections import deque -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") +dq = deque([]) +# pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす) +dq.append(0) +while dq: +    a = dq.pop() +    b = col[a] +    for i in range(2): +        for ne in e[a][i]: +            if col[ne] == -1: +                col[ne] = b ^ i +                dq.appendleft(ne) +print(*col, sep="\n")