from collections import deque



def bfs(start, g, visited):

    q = deque([start])

    visited[start] = 0

    while q:

        curr_node = q.popleft()

        for next_node, w in g[curr_node]:

            if visited[next_node] >= 0: continue

            visited[next_node] = (visited[curr_node] + w)%2

            q.append(next_node)





n = int(eval(input()))

gl = [ [] for _ in range(n+1)]

for _ in range(n-1):

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

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

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

visited = [-1] * (n+1)

bfs(1, gl, visited)



for v in visited[1:]:

    if v%2 == 0: print((0))

    else: print((1))
import sys

from collections import deque

input = sys.stdin.readline

sys.setrecursionlimit(10**6)



def dfs(start,n,g):

    visited = [-1]*(n+1)

    visited[start] = 0

    stack = deque([start])

    while stack:

        c_node = stack.pop()

        for neib, dist in g[c_node]:

            if visited[neib] != -1: continue

            visited[neib] = visited[c_node] + dist

            stack.append(neib)

    return visited

    



N = int(eval(input()))

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

visited = [-1] * (N+1)



for _ in range(N-1):

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

    w%=2

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

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



visited = dfs(1,N,g)

for p in visited[1:]:

    print((p%2))

    



from collections import deque


def bfs(start, g, visited):
    q = deque([start])
    visited[start] = 0
    while q:
        curr_node = q.popleft()
        for next_node, w in g[curr_node]:
            if visited[next_node] >= 0:
                continue
            visited[next_node] = (visited[curr_node] + w) % 2
            q.append(next_node)


n = int(eval(input()))
gl = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    gl[u].append((v, w))
    gl[v].append((u, w))
visited = [-1] * (n + 1)
bfs(1, gl, visited)
for v in visited[1:]:
    if v % 2 == 0:
        print((0))
    else:
        print((1))

import sys
from collections import deque

input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def dfs(start, n, g):
    visited = [-1] * (n + 1)
    visited[start] = 0
    stack = deque([start])
    while stack:
        c_node = stack.pop()
        for neib, dist in g[c_node]:
            if visited[neib] != -1:
                continue
            visited[neib] = visited[c_node] + dist
            stack.append(neib)
    return visited


N = int(eval(input()))
g = [[] for _ in range(N + 1)]
visited = [-1] * (N + 1)
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    w %= 2
    g[u].append((v, w))
    g[v].append((u, w))
visited = dfs(1, N, g)
for p in visited[1:]:
    print((p % 2))

+import sys - -def bfs(start, g, visited): -    q = deque([start]) -    visited[start] = 0 -    while q: -        curr_node = q.popleft() -        for next_node, w in g[curr_node]: -            if visited[next_node] >= 0: -                continue -            visited[next_node] = (visited[curr_node] + w) % 2 -            q.append(next_node) +input = sys.stdin.readline +sys.setrecursionlimit(10**6) -n = int(eval(input())) -gl = [[] for _ in range(n + 1)] -for _ in range(n - 1): +def dfs(start, n, g): +    visited = [-1] * (n + 1) +    visited[start] = 0 +    stack = deque([start]) +    while stack: +        c_node = stack.pop() +        for neib, dist in g[c_node]: +            if visited[neib] != -1: +                continue +            visited[neib] = visited[c_node] + dist +            stack.append(neib) +    return visited + + +N = int(eval(input())) +g = [[] for _ in range(N + 1)] +visited = [-1] * (N + 1) +for _ in range(N - 1): -    gl[u].append((v, w)) -    gl[v].append((u, w)) -visited = [-1] * (n + 1) -bfs(1, gl, visited) -for v in visited[1:]: -    if v % 2 == 0: -        print((0)) -    else: -        print((1)) +    w %= 2 +    g[u].append((v, w)) +    g[v].append((u, w)) +visited = dfs(1, N, g) +for p in visited[1:]: +    print((p % 2))