N=int(eval(input()))

p=[[]for _ in range(N+1)]

for _ in range(N-1):

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

  p[u].append((v,w))

  p[v].append((u,w))

s=[(1,0)]

l=[-1]*N

while s:

  a,w=s.pop()

  l[a-1]=w%2

  for b,c in p[a]:

    if l[b-1]==-1:

      s.append((b,w+c))

for i in l:

	print(i)

n=int(eval(input()))

q=[[] for i in range(n+1)]

for i in range(n-1):

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

    q[a].append((b,c))

    q[b].append((a,c))



l=[-1]*n

s=[(1,0)]

while s:

    a,w=s.pop()

    l[a-1]=w%2

    for b,c in q[a]:

        if l[b-1]==-1:

            s.append((b,w+c))



for i in l:

    print(i)
N = int(eval(input()))
p = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    p[u].append((v, w))
    p[v].append((u, w))
s = [(1, 0)]
l = [-1] * N
while s:
    a, w = s.pop()
    l[a - 1] = w % 2
    for b, c in p[a]:
        if l[b - 1] == -1:
            s.append((b, w + c))
for i in l:
    print(i)

n = int(eval(input()))
q = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    q[a].append((b, c))
    q[b].append((a, c))
l = [-1] * n
s = [(1, 0)]
while s:
    a, w = s.pop()
    l[a - 1] = w % 2
    for b, c in q[a]:
        if l[b - 1] == -1:
            s.append((b, w + c))
for i in l:
    print(i)

-N = int(eval(input())) -p = [[] for _ in range(N + 1)] -for _ in range(N - 1): -    u, v, w = list(map(int, input().split())) -    p[u].append((v, w)) -    p[v].append((u, w)) +n = int(eval(input())) +q = [[] for i in range(n + 1)] +for i in range(n - 1): +    a, b, c = list(map(int, input().split())) +    q[a].append((b, c)) +    q[b].append((a, c)) +l = [-1] * n -l = [-1] * N -    for b, c in p[a]: +    for b, c in q[a]: