We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:    * For any two vertices painted in the same color, the distance between them is an even number.  Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
#!/usr/bin/env python
N = int(input())
L = [[int(i) for i in input().split()] for i in range(N-1)] 
b, w = [], []

for l in L:
    if l[2] % 2 == 0:
        if l[0] in b or l[1] in b:
            b.append(l[0])
            b.append(l[1])
        elif l[0] in w or l[1] in w:
            w.append(l[0])
            w.append(l[1])
        else:
            b.append(l[0])
            b.append(l[1])
    else:
        if l[0] in b:
            w.append(l[1])
        elif l[0] in w:
            b.append(l[1])
        else:
            if l[1] not in b:
                b.append(l[1])
                w.append(l[0])
            else:
                b.append(l[0])
                w.append(l[1])
b = list(set(b))
w = list(set(w))
for i in range(1, N+1):
    if i in b:
        print('1')
    else:
        print('0')

#!/usr/bin/env python
from math import *

N=int(input())
tonaris = [[] for i in range(N)]
for _ in range(1,N):
    u,v,w = tuple(map(int,input().split()))
    u -= 1
    v -= 1
    w = w%2
    tonaris[u].append((v,w))
    tonaris[v].append((u,w))


colors = [None for i in range(N)]

q = [0]
colors[0]=0
while len(q)!=0:
    u = q.pop()
    for v,w in tonaris[u]:
        tonaris[v].remove((u,w))
        colors[v] = colors[u] ^ w
        q.append(v)

for color in colors:
    print(color)
