import sys

sys.setrecursionlimit(10**7)

N = int(eval(input()))

L = [-1 for i in range(N)]

flg = [0 for i in range(N)]

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

for i in range(N-1):

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

  M[u-1].append([v-1, w%2])

  M[v-1].append([u-1, w%2])

L[0] = 0

def dist(m, d):

  L[m] = d % 2

  for i in M[m]:

    if L[i[0]] == -1:

      dist(i[0], i[1] + d)

dist(0, 0)

for i in range(N):

  print((L[i]))
N = int(eval(input()))

D = {i: [] for i in range(N)}

distD = {}

for i in range(N-1):

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

    u -= 1

    v -= 1

    D[u].append(v)

    D[v].append(u)

    distD[u*N+v], distD[v*N+u] = w, w

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

clr[0] = 0

s = [0]

pnt = 0

cnt = 1

while pnt < cnt:

    n = cnt

    for i in range(pnt, cnt):

        L = D[s[i]]

        for j in L:

            if clr[j] == -1:

                clr[j] = (clr[s[i]] + distD[s[i]*N+j]) % 2

                s.append(j)

                cnt += 1

    pnt = n

for i in range(N):

    print((clr[i]))
import sys

sys.setrecursionlimit(10**7)
N = int(eval(input()))
L = [-1 for i in range(N)]
flg = [0 for i in range(N)]
M = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = list(map(int, input().split()))
    M[u - 1].append([v - 1, w % 2])
    M[v - 1].append([u - 1, w % 2])
L[0] = 0


def dist(m, d):
    L[m] = d % 2
    for i in M[m]:
        if L[i[0]] == -1:
            dist(i[0], i[1] + d)


dist(0, 0)
for i in range(N):
    print((L[i]))

N = int(eval(input()))
D = {i: [] for i in range(N)}
distD = {}
for i in range(N - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    D[u].append(v)
    D[v].append(u)
    distD[u * N + v], distD[v * N + u] = w, w
clr = [-1 for _ in range(N)]
clr[0] = 0
s = [0]
pnt = 0
cnt = 1
while pnt < cnt:
    n = cnt
    for i in range(pnt, cnt):
        L = D[s[i]]
        for j in L:
            if clr[j] == -1:
                clr[j] = (clr[s[i]] + distD[s[i] * N + j]) % 2
                s.append(j)
                cnt += 1
    pnt = n
for i in range(N):
    print((clr[i]))

-import sys - -sys.setrecursionlimit(10**7) -L = [-1 for i in range(N)] -flg = [0 for i in range(N)] -M = [[] for i in range(N)] +D = {i: [] for i in range(N)} +distD = {} -    M[u - 1].append([v - 1, w % 2]) -    M[v - 1].append([u - 1, w % 2]) -L[0] = 0 - - -def dist(m, d): -    L[m] = d % 2 -    for i in M[m]: -        if L[i[0]] == -1: -            dist(i[0], i[1] + d) - - -dist(0, 0) +    u -= 1 +    v -= 1 +    D[u].append(v) +    D[v].append(u) +    distD[u * N + v], distD[v * N + u] = w, w +clr = [-1 for _ in range(N)] +clr[0] = 0 +s = [0] +pnt = 0 +cnt = 1 +while pnt < cnt: +    n = cnt +    for i in range(pnt, cnt): +        L = D[s[i]] +        for j in L: +            if clr[j] == -1: +                clr[j] = (clr[s[i]] + distD[s[i] * N + j]) % 2 +                s.append(j) +                cnt += 1 +    pnt = n -    print((L[i])) +    print((clr[i]))