from collections import deque

n=int(eval(input()))

edge=[[] for i in range(n)]

if n==1:

  print((0))

  exit()

col=[-1 for i in range(n)]

for i in range(n-1):

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

  u-=1

  v-=1

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

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

def dfs(edge,col):

  stack=deque([0])

  col[0]=0

  while stack:

    x=stack.pop()

    for i,j in edge[x]:

      newx=i

      if col[i]==-1:

        col[newx]=(col[x]+j)%2

        stack.append(newx)

  return col

for i in range(n):

  print((dfs(edge,col)[i]))
from collections import deque

n=int(eval(input()))

edges=[[] for _ in range(n)]

visited=[-1 for _ in range(n)]

for i in range(n-1):

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

  edges[u-1].append((v-1,w))

  edges[v-1].append((u-1,w))

def dfs(edges,visited):

  stack=deque([0])

  visited[0]=0

  while stack:

    x=stack.pop()

    for newx,w in edges[x]:

      if visited[newx]==-1:

        if w%2:

          visited[newx]=1-visited[x]

        else:

          visited[newx]=visited[x]

        stack.append(newx)

  return visited

for i in dfs(edges,visited):

  print(i)
from collections import deque

n = int(eval(input()))
edge = [[] for i in range(n)]
if n == 1:
    print((0))
    exit()
col = [-1 for i in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    edge[u].append((v, w))
    edge[v].append((u, w))


def dfs(edge, col):
    stack = deque([0])
    col[0] = 0
    while stack:
        x = stack.pop()
        for i, j in edge[x]:
            newx = i
            if col[i] == -1:
                col[newx] = (col[x] + j) % 2
                stack.append(newx)
    return col


for i in range(n):
    print((dfs(edge, col)[i]))

from collections import deque

n = int(eval(input()))
edges = [[] for _ in range(n)]
visited = [-1 for _ in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    edges[u - 1].append((v - 1, w))
    edges[v - 1].append((u - 1, w))


def dfs(edges, visited):
    stack = deque([0])
    visited[0] = 0
    while stack:
        x = stack.pop()
        for newx, w in edges[x]:
            if visited[newx] == -1:
                if w % 2:
                    visited[newx] = 1 - visited[x]
                else:
                    visited[newx] = visited[x]
                stack.append(newx)
    return visited


for i in dfs(edges, visited):
    print(i)

-edge = [[] for i in range(n)] -if n == 1: -    print((0)) -    exit() -col = [-1 for i in range(n)] +edges = [[] for _ in range(n)] +visited = [-1 for _ in range(n)] -    u -= 1 -    v -= 1 -    edge[u].append((v, w)) -    edge[v].append((u, w)) +    edges[u - 1].append((v - 1, w)) +    edges[v - 1].append((u - 1, w)) -def dfs(edge, col): +def dfs(edges, visited): -    col[0] = 0 +    visited[0] = 0 -        for i, j in edge[x]: -            newx = i -            if col[i] == -1: -                col[newx] = (col[x] + j) % 2 +        for newx, w in edges[x]: +            if visited[newx] == -1: +                if w % 2: +                    visited[newx] = 1 - visited[x] +                else: +                    visited[newx] = visited[x] -    return col +    return visited -for i in range(n): -    print((dfs(edge, col)[i])) +for i in dfs(edges, visited): +    print(i)