import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**6)



def dfs(curr_v, pare_v, curr_sum, visited, g):

    if curr_sum%2 == 0:

        visited[curr_v] = 0

    else:

        visited[curr_v] = 1

    for neib_vw in g[curr_v]:

        if neib_vw[0] == pare_v: continue

        dfs(neib_vw[0], curr_v, curr_sum+neib_vw[1], visited, g)

    



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))



dfs(1, -1, 0, visited, g)

for p in visited[1:]:

    print(p)

    



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

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


def dfs(curr_v, pare_v, curr_sum, visited, g):
    if curr_sum % 2 == 0:
        visited[curr_v] = 0
    else:
        visited[curr_v] = 1
    for neib_vw in g[curr_v]:
        if neib_vw[0] == pare_v:
            continue
        dfs(neib_vw[0], curr_v, curr_sum + neib_vw[1], visited, g)


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))
dfs(1, -1, 0, visited, g)
for p in visited[1:]:
    print(p)

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 - -input = sys.stdin.readline -sys.setrecursionlimit(10**6) +from collections import deque -def dfs(curr_v, pare_v, curr_sum, visited, g): -    if curr_sum % 2 == 0: -        visited[curr_v] = 0 -    else: -        visited[curr_v] = 1 -    for neib_vw in g[curr_v]: -        if neib_vw[0] == pare_v: -            continue -        dfs(neib_vw[0], curr_v, curr_sum + neib_vw[1], visited, g) +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())) -g = [[] for _ in range(N + 1)] -visited = [-1] * (N + 1) -for _ in range(N - 1): +n = int(eval(input())) +gl = [[] for _ in range(n + 1)] +for _ in range(n - 1): -    w %= 2 -    g[u].append((v, w)) -    g[v].append((u, w)) -dfs(1, -1, 0, visited, g) -for p in visited[1:]: -    print(p) +    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))