N = int(eval(input()))

edge = [[] for _ in range(N)]

for _ in range(N-1):

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

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

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



dist = [-1] * N

dist[0] = 0

que = [0]

while que:

    u = que.pop()

    d = dist[u]



    for v,w in edge[u]:

        if dist[v] > 0:

            continue

        dist[v] = d + w

        que.append(v)



for d in dist:

    if d % 2 == 0:

        print((0))

    else:

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

edge = [[] for _ in range(N)]

for _ in range(N-1):

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

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

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



dist = [-1] * N

dist[0] = 0

stack = [0]

while stack:

    u = stack.pop()

    d = dist[u]



    for v,w in edge[u]:

        if dist[v] > 0:

            continue

        dist[v] = d + w

        stack.append(v)



for d in dist:

    if d % 2 == 0:

        print((0))

    else:

        print((1))
N = int(eval(input()))
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    edge[u - 1].append((v - 1, w))
    edge[v - 1].append((u - 1, w))
dist = [-1] * N
dist[0] = 0
que = [0]
while que:
    u = que.pop()
    d = dist[u]
    for v, w in edge[u]:
        if dist[v] > 0:
            continue
        dist[v] = d + w
        que.append(v)
for d in dist:
    if d % 2 == 0:
        print((0))
    else:
        print((1))

N = int(eval(input()))
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    edge[u - 1].append((v - 1, w))
    edge[v - 1].append((u - 1, w))
dist = [-1] * N
dist[0] = 0
stack = [0]
while stack:
    u = stack.pop()
    d = dist[u]
    for v, w in edge[u]:
        if dist[v] > 0:
            continue
        dist[v] = d + w
        stack.append(v)
for d in dist:
    if d % 2 == 0:
        print((0))
    else:
        print((1))

-que = [0] -while que: -    u = que.pop() +stack = [0] +while stack: +    u = stack.pop() -        que.append(v) +        stack.append(v)