import sys

sys.setrecursionlimit(10 ** 6)

N = int(eval(input()))

uvw = [list(map(int, input().split())) for i in range(N - 1)]

R = [-1] * N

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

for i in range(N - 1):

    Q[uvw[i][0] - 1].append([uvw[i][1], uvw[i][2]])

    Q[uvw[i][1] - 1].append([uvw[i][0], uvw[i][2]])



def func(i, s, d, l):

    

    if R[i] != -1:

        return



    if R[i] == -1:

        if l %2 == 0:

            R[i] = s

        else:

            R[i] = d

            tmp = s

            s = d

            d = tmp

    for j in range(len(Q[i])):

        func(Q[i][j][0] - 1, s, d, Q[i][j][1])



func(uvw[0][0] - 1, 0, 1, 0)

for i in range(len(R)):

    print((R[i]))
import sys

sys.setrecursionlimit(10 ** 6)



N = int(eval(input()))

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

for i in range(N - 1):

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

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

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

S = [-1] * N



def func(x, w, c):

    if w % 2 != 0:

        c = 1 - c

    S[x] = c

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

        x1 = G[x][i][0] - 1

        if S[x1] != -1:

            continue

        w1 = G[x][i][1]

        func(x1, w1, c)



func(G[0][0][0] - 1, G[0][0][1], 0)

for i in range(N):

    print((S[i]))
import sys

sys.setrecursionlimit(10**6)
N = int(eval(input()))
uvw = [list(map(int, input().split())) for i in range(N - 1)]
R = [-1] * N
Q = [[] for i in range(N)]
for i in range(N - 1):
    Q[uvw[i][0] - 1].append([uvw[i][1], uvw[i][2]])
    Q[uvw[i][1] - 1].append([uvw[i][0], uvw[i][2]])


def func(i, s, d, l):
    if R[i] != -1:
        return
    if R[i] == -1:
        if l % 2 == 0:
            R[i] = s
        else:
            R[i] = d
            tmp = s
            s = d
            d = tmp
    for j in range(len(Q[i])):
        func(Q[i][j][0] - 1, s, d, Q[i][j][1])


func(uvw[0][0] - 1, 0, 1, 0)
for i in range(len(R)):
    print((R[i]))

import sys

sys.setrecursionlimit(10**6)
N = int(eval(input()))
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b, w = list(map(int, input().split()))
    G[a - 1].append([b, w])
    G[b - 1].append([a, w])
S = [-1] * N


def func(x, w, c):
    if w % 2 != 0:
        c = 1 - c
    S[x] = c
    for i in range(len(G[x])):
        x1 = G[x][i][0] - 1
        if S[x1] != -1:
            continue
        w1 = G[x][i][1]
        func(x1, w1, c)


func(G[0][0][0] - 1, G[0][0][1], 0)
for i in range(N):
    print((S[i]))

-uvw = [list(map(int, input().split())) for i in range(N - 1)] -R = [-1] * N -Q = [[] for i in range(N)] +G = [[] for i in range(N)] -    Q[uvw[i][0] - 1].append([uvw[i][1], uvw[i][2]]) -    Q[uvw[i][1] - 1].append([uvw[i][0], uvw[i][2]]) +    a, b, w = list(map(int, input().split())) +    G[a - 1].append([b, w]) +    G[b - 1].append([a, w]) +S = [-1] * N -def func(i, s, d, l): -    if R[i] != -1: -        return -    if R[i] == -1: -        if l % 2 == 0: -            R[i] = s -        else: -            R[i] = d -            tmp = s -            s = d -            d = tmp -    for j in range(len(Q[i])): -        func(Q[i][j][0] - 1, s, d, Q[i][j][1]) +def func(x, w, c): +    if w % 2 != 0: +        c = 1 - c +    S[x] = c +    for i in range(len(G[x])): +        x1 = G[x][i][0] - 1 +        if S[x1] != -1: +            continue +        w1 = G[x][i][1] +        func(x1, w1, c) -func(uvw[0][0] - 1, 0, 1, 0) -for i in range(len(R)): -    print((R[i])) +func(G[0][0][0] - 1, G[0][0][1], 0) +for i in range(N): +    print((S[i]))