from collections import defaultdict

import sys



sys.setrecursionlimit(1000000)



d = defaultdict(list)

cost = defaultdict(int)

N = int(eval(input()))



for _ in range(N-1):

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

    d[u].append(v)

    d[v].append(u)

    cost[(u, v)] = w



visited = [False]*(N+1)

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



def dfs(x):

    visited[x]=True

    if color[x]==-1:

        color[x] = 0



    for y in d[x]:

        if visited[y]:

            continue

        

        c = cost[(x, y) if x<y else (y, x)]

        if c%2==0:

            color[y] = 0 if color[x]==0 else 1

        else:

            color[y] = 1 if color[x]==0 else 0

        dfs(y)



dfs(1)

for i in color[1:]:

    print(i)
from collections import defaultdict

import sys

sys.setrecursionlimit(1000000)



d = defaultdict(list)

cost = defaultdict(int)

N = int(eval(input()))



for _ in range(N-1):

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

    d[u].append(v)

    d[v].append(u)

    cost[(u, v)] = w



visited = [False]*(N+1)

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

color[1] = 0



def dfs(x):

    visited[x]=True

    for y in d[x]:

        if visited[y]:continue

        c = cost[(x, y) if x<y else (y, x)]

        color[y] = color[x]^1 if c%2 else color[x]  

        dfs(y)



dfs(1)

for i in color[1:]:

    print(i)
from collections import defaultdict
import sys

sys.setrecursionlimit(1000000)
d = defaultdict(list)
cost = defaultdict(int)
N = int(eval(input()))
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    d[u].append(v)
    d[v].append(u)
    cost[(u, v)] = w
visited = [False] * (N + 1)
color = [-1] * (N + 1)


def dfs(x):
    visited[x] = True
    if color[x] == -1:
        color[x] = 0
    for y in d[x]:
        if visited[y]:
            continue
        c = cost[(x, y) if x < y else (y, x)]
        if c % 2 == 0:
            color[y] = 0 if color[x] == 0 else 1
        else:
            color[y] = 1 if color[x] == 0 else 0
        dfs(y)


dfs(1)
for i in color[1:]:
    print(i)

from collections import defaultdict
import sys

sys.setrecursionlimit(1000000)
d = defaultdict(list)
cost = defaultdict(int)
N = int(eval(input()))
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    d[u].append(v)
    d[v].append(u)
    cost[(u, v)] = w
visited = [False] * (N + 1)
color = [-1] * (N + 1)
color[1] = 0


def dfs(x):
    visited[x] = True
    for y in d[x]:
        if visited[y]:
            continue
        c = cost[(x, y) if x < y else (y, x)]
        color[y] = color[x] ^ 1 if c % 2 else color[x]
        dfs(y)


dfs(1)
for i in color[1:]:
    print(i)

+color[1] = 0 -    if color[x] == -1: -        color[x] = 0 -        if c % 2 == 0: -            color[y] = 0 if color[x] == 0 else 1 -        else: -            color[y] = 1 if color[x] == 0 else 0 +        color[y] = color[x] ^ 1 if c % 2 else color[x]