n = int(eval(input()))

d = [[] for i in range(n)]

for i in range(n-1):

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

    d[u-1].append([v-1,w])

    d[v-1].append([u-1,w])

ans = [-1]*n

ans[0]=0

q = [0]

cnt = 0



while q:

    u = q.pop()

    for v,w in d[u]:

        if ans[v]==-1:

            if w%2==0:

                ans[v]=ans[u]

            else:

                ans[v]=(ans[u]+1)%2

            q.append(v)

for i in ans:

    print(i)
n = int(eval(input()))

d = [[] for i in range(n)]

for i in range(n-1):

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

    d[u-1].append([v-1,w])

    d[v-1].append([u-1,w])



ans = [[] for i in range(n)]

ans[0].append(0)

q = [0]



while q:

    x = q.pop()

    for u,w in d[x]:

        if not ans[u]:

            buf = ans[x][0]

            if w%2==1:

                buf = (buf+1)%2

            ans[u].append(buf)

            q.append(u)



for i in ans:

    print((*i))

n = int(eval(input()))
d = [[] for i in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    d[u - 1].append([v - 1, w])
    d[v - 1].append([u - 1, w])
ans = [-1] * n
ans[0] = 0
q = [0]
cnt = 0
while q:
    u = q.pop()
    for v, w in d[u]:
        if ans[v] == -1:
            if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
            q.append(v)
for i in ans:
    print(i)

n = int(eval(input()))
d = [[] for i in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    d[u - 1].append([v - 1, w])
    d[v - 1].append([u - 1, w])
ans = [[] for i in range(n)]
ans[0].append(0)
q = [0]
while q:
    x = q.pop()
    for u, w in d[x]:
        if not ans[u]:
            buf = ans[x][0]
            if w % 2 == 1:
                buf = (buf + 1) % 2
            ans[u].append(buf)
            q.append(u)
for i in ans:
    print((*i))

-ans = [-1] * n -ans[0] = 0 +ans = [[] for i in range(n)] +ans[0].append(0) -cnt = 0 -    u = q.pop() -    for v, w in d[u]: -        if ans[v] == -1: -            if w % 2 == 0: -                ans[v] = ans[u] -            else: -                ans[v] = (ans[u] + 1) % 2 -            q.append(v) +    x = q.pop() +    for u, w in d[x]: +        if not ans[u]: +            buf = ans[x][0] +            if w % 2 == 1: +                buf = (buf + 1) % 2 +            ans[u].append(buf) +            q.append(u) -    print(i) +    print((*i))