import sys

sys.setrecursionlimit(10 ** 8)



N = int(eval(input()))

        

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

for _ in range(N - 1):

    a, b, c = list(map(int, input().split()))

    G[a - 1].append([b - 1, c])

    G[b - 1].append([a - 1, c])

    

color = [0] * N



def dfs(v, c):

    if color[v] == 0:

        color[v] = c

    for i in range(len(G[v])):

        if color[G[v][i][0]] == 0:

            if G[v][i][1] % 2 == 0:

                dfs(G[v][i][0], color[v])

            else:

                dfs(G[v][i][0] , -color[v])

                

for i in range(N):

    dfs(i, 1)

    # print(color)

    

for i in range(N):

    if color[i] == 1:

        print((0))

    else:

        print((1))
N = int(eval(input()))

        

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

for _ in range(N - 1):

    a, b, c = list(map(int, input().split()))

    G[a - 1].append([b - 1, c])

    G[b - 1].append([a - 1, c])

    

color = [-1] * N

color[0] = 0

Q = [0]



while len(Q) != 0:

    cur = Q.pop()

    for to, dist in G[cur]:

        if color[to] == -1:

            color[to] = (color[cur] + dist) % 2

            Q.append(to)

            

for i in range(N):

    print((color[i]))
import sys

sys.setrecursionlimit(10**8)
N = int(eval(input()))
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
color = [0] * N


def dfs(v, c):
    if color[v] == 0:
        color[v] = c
    for i in range(len(G[v])):
        if color[G[v][i][0]] == 0:
            if G[v][i][1] % 2 == 0:
                dfs(G[v][i][0], color[v])
            else:
                dfs(G[v][i][0], -color[v])


for i in range(N):
    dfs(i, 1)
    # print(color)
for i in range(N):
    if color[i] == 1:
        print((0))
    else:
        print((1))

N = int(eval(input()))
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
color = [-1] * N
color[0] = 0
Q = [0]
while len(Q) != 0:
    cur = Q.pop()
    for to, dist in G[cur]:
        if color[to] == -1:
            color[to] = (color[cur] + dist) % 2
            Q.append(to)
for i in range(N):
    print((color[i]))

-import sys - -sys.setrecursionlimit(10**8) -color = [0] * N - - -def dfs(v, c): -    if color[v] == 0: -        color[v] = c -    for i in range(len(G[v])): -        if color[G[v][i][0]] == 0: -            if G[v][i][1] % 2 == 0: -                dfs(G[v][i][0], color[v]) -            else: -                dfs(G[v][i][0], -color[v]) - - +color = [-1] * N +color[0] = 0 +Q = [0] +while len(Q) != 0: +    cur = Q.pop() +    for to, dist in G[cur]: +        if color[to] == -1: +            color[to] = (color[cur] + dist) % 2 +            Q.append(to) -    dfs(i, 1) -    # print(color) -for i in range(N): -    if color[i] == 1: -        print((0)) -    else: -        print((1)) +    print((color[i]))