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.
from collections import deque

def bfs(colors, links):
    q = deque([(0, 0)])
    
    while q:
        v, current = q.popleft()

        if current % 2 == 0:
            colors[v] = 0
        else:
            colors[v] = 1

        for next_v, distance in links[v]:
            if colors[next_v] != -1: continue

            q.append((next_v, current + distance))
        
def solve():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(N-1)]
    cs = [-1] * N
    cs[0] = 0

    links = [[] for _ in range(N)]
    for u, v, w in A:
        v -= 1
        u -= 1
        links[v].append((u, w))
        links[u].append((v, w))

    bfs(cs, links)

    print('\n'.join(map(str, cs)))

print(solve())
from collections import deque

def bfs(colors, links):
    q = deque([(0, 0)])
    
    while q:
        v, current = q.popleft()

        for next_v, distance in links[v]:
            if colors[next_v] != -1: continue
        
            if (current+distance) % 2 == 0:
                colors[next_v] = 0
            else:
                colors[next_v] = 1

            q.append((next_v, current + distance))
        
def solve():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(N-1)]
    cs = [-1] * N
    cs[0] = 0

    links = [[] for _ in range(N)]
    for u, v, w in A:
        v -= 1
        u -= 1
        links[v].append((u, w))
        links[u].append((v, w))

    bfs(cs, links)

    print('\n'.join(map(str, cs)))

solve()