import sys

sys.setrecursionlimit(100**4)



class Edge():

	def __init__(self, v, w):

		self._v = v

		self._w = w

	def v(self):

		return self._v

	def w(self):

		return self._w



def dfs(v, g, colors, color = 0):

	colors[v] = color

	if not len(g[v]):

		return

	for nv in g[v]:

		if colors[nv.v()] != -1:

			continue

		nc = color if nv.w() % 2 == 0 else 1 - color

		dfs(nv.v(), g, colors, nc)



def resolve():

	n = int(eval(input()))

	colors = [-1]*n

	g = [list() for _ in range(n)]

	for _ in range(n-1):

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

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

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

	for i in range(n):

		if colors[i] != -1:

			continue

		dfs(i, g, colors)

	for c in colors:

		print(c)

resolve()
import sys

from io import StringIO

import unittest



sys.setrecursionlimit(100**3)



def coloring(v, p, vs, cs, color):

	cs[v] = color

	for e in vs[v]:

		if e[0] == p:

			continue

		nc = color if e[1] % 2 == 0 else 1 - color

		coloring(e[0], v, vs, cs, nc)



def resolve():

	n = int(eval(input()))

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

	cs = [None]*n

	for i in range(n-1):

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

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

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

	coloring(0, None, vs, cs, 1)

	for i in cs:

		print(i)

resolve()
import sys

sys.setrecursionlimit(100**4)


class Edge:
    def __init__(self, v, w):
        self._v = v
        self._w = w

    def v(self):
        return self._v

    def w(self):
        return self._w


def dfs(v, g, colors, color=0):
    colors[v] = color
    if not len(g[v]):
        return
    for nv in g[v]:
        if colors[nv.v()] != -1:
            continue
        nc = color if nv.w() % 2 == 0 else 1 - color
        dfs(nv.v(), g, colors, nc)


def resolve():
    n = int(eval(input()))
    colors = [-1] * n
    g = [list() for _ in range(n)]
    for _ in range(n - 1):
        u, v, w = list(map(int, input().split()))
        g[v - 1].append(Edge(u - 1, w))
        g[u - 1].append(Edge(v - 1, w))
    for i in range(n):
        if colors[i] != -1:
            continue
        dfs(i, g, colors)
    for c in colors:
        print(c)


resolve()

import sys
from io import StringIO
import unittest

sys.setrecursionlimit(100**3)


def coloring(v, p, vs, cs, color):
    cs[v] = color
    for e in vs[v]:
        if e[0] == p:
            continue
        nc = color if e[1] % 2 == 0 else 1 - color
        coloring(e[0], v, vs, cs, nc)


def resolve():
    n = int(eval(input()))
    vs = [[] for _ in range(n)]
    cs = [None] * n
    for i in range(n - 1):
        u, v, w = list(map(int, input().split()))
        vs[u - 1].append([v - 1, w])
        vs[v - 1].append([u - 1, w])
    coloring(0, None, vs, cs, 1)
    for i in cs:
        print(i)


resolve()

+from io import StringIO +import unittest -sys.setrecursionlimit(100**4) +sys.setrecursionlimit(100**3) -class Edge: -    def __init__(self, v, w): -        self._v = v -        self._w = w - -    def v(self): -        return self._v - -    def w(self): -        return self._w - - -def dfs(v, g, colors, color=0): -    colors[v] = color -    if not len(g[v]): -        return -    for nv in g[v]: -        if colors[nv.v()] != -1: +def coloring(v, p, vs, cs, color): +    cs[v] = color +    for e in vs[v]: +        if e[0] == p: -        nc = color if nv.w() % 2 == 0 else 1 - color -        dfs(nv.v(), g, colors, nc) +        nc = color if e[1] % 2 == 0 else 1 - color +        coloring(e[0], v, vs, cs, nc) -    colors = [-1] * n -    g = [list() for _ in range(n)] -    for _ in range(n - 1): +    vs = [[] for _ in range(n)] +    cs = [None] * n +    for i in range(n - 1): -        g[v - 1].append(Edge(u - 1, w)) -        g[u - 1].append(Edge(v - 1, w)) -    for i in range(n): -        if colors[i] != -1: -            continue -        dfs(i, g, colors) -    for c in colors: -        print(c) +        vs[u - 1].append([v - 1, w]) +        vs[v - 1].append([u - 1, w]) +    coloring(0, None, vs, cs, 1) +    for i in cs: +        print(i)