import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)





def dfs(v, c, C, visited, G):

    visited[v] = True

    C[v] = c



    for nv, w in G[v]:

        if visited[nv]:

            continue

        dfs(nv, c^w, C, visited, G)





def main():

    N = int(eval(input()))

    

    G = [[] for _ in range(N)]

    for _ in range(N-1):

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

        G[u-1].append([v-1, w%2])

        G[v-1].append([u-1, w%2])

    # print(G)



    C = [0]*N

    visited = [False]*N

    dfs(0, 0, C, visited, G)

    for c in C:

        print(c)

    

        





if __name__ == '__main__':

    main()
from functools import reduce

from fractions import gcd

import math

import bisect

import itertools

import sys

sys.setrecursionlimit(10**7)

input = sys.stdin.readline

INF = float("inf")

MOD = 1000000007





class Edge:

    def __init__(self, to, cost):

        self.to = to

        self.cost = cost





visited = []

vertex = []

def dfs(G, v, d):

    visited[v] = True

    if d % 2 == 0:

        vertex[v] = 0

    else:

        vertex[v] = 1



    for edge in G[v]:

        nv = edge.to

        if visited[nv]:

            continue

        nd = d + edge.cost

        dfs(G, nv, nd)





def main():

    N = int(eval(input()))

    G = [[] for _ in range(N)]

    for _ in range(N-1):

        a, b, cost = list(map(int, input().split()))

        a -= 1; b -= 1

        G[a].append(Edge(b, cost))

        G[b].append(Edge(a, cost))



    for _ in range(N):

        visited.append(False)

        vertex.append(0)

    

    dfs(G, 0, 0)



    for v in vertex:

        print(v)





if __name__ == '__main__':

    main()
import sys

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


def dfs(v, c, C, visited, G):
    visited[v] = True
    C[v] = c
    for nv, w in G[v]:
        if visited[nv]:
            continue
        dfs(nv, c ^ w, C, visited, G)


def main():
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = list(map(int, input().split()))
        G[u - 1].append([v - 1, w % 2])
        G[v - 1].append([u - 1, w % 2])
    # print(G)
    C = [0] * N
    visited = [False] * N
    dfs(0, 0, C, visited, G)
    for c in C:
        print(c)


if __name__ == "__main__":
    main()

from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 1000000007


class Edge:
    def __init__(self, to, cost):
        self.to = to
        self.cost = cost


visited = []
vertex = []


def dfs(G, v, d):
    visited[v] = True
    if d % 2 == 0:
        vertex[v] = 0
    else:
        vertex[v] = 1
    for edge in G[v]:
        nv = edge.to
        if visited[nv]:
            continue
        nd = d + edge.cost
        dfs(G, nv, nd)


def main():
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b, cost = list(map(int, input().split()))
        a -= 1
        b -= 1
        G[a].append(Edge(b, cost))
        G[b].append(Edge(a, cost))
    for _ in range(N):
        visited.append(False)
        vertex.append(0)
    dfs(G, 0, 0)
    for v in vertex:
        print(v)


if __name__ == "__main__":
    main()

+from functools import reduce +from fractions import gcd +import math +import bisect +import itertools +sys.setrecursionlimit(10**7) -sys.setrecursionlimit(10**7) +INF = float("inf") +MOD = 1000000007 -def dfs(v, c, C, visited, G): +class Edge: +    def __init__(self, to, cost): +        self.to = to +        self.cost = cost + + +visited = [] +vertex = [] + + +def dfs(G, v, d): -    C[v] = c -    for nv, w in G[v]: +    if d % 2 == 0: +        vertex[v] = 0 +    else: +        vertex[v] = 1 +    for edge in G[v]: +        nv = edge.to -        dfs(nv, c ^ w, C, visited, G) +        nd = d + edge.cost +        dfs(G, nv, nd) -        u, v, w = list(map(int, input().split())) -        G[u - 1].append([v - 1, w % 2]) -        G[v - 1].append([u - 1, w % 2]) -    # print(G) -    C = [0] * N -    visited = [False] * N -    dfs(0, 0, C, visited, G) -    for c in C: -        print(c) +        a, b, cost = list(map(int, input().split())) +        a -= 1 +        b -= 1 +        G[a].append(Edge(b, cost)) +        G[b].append(Edge(a, cost)) +    for _ in range(N): +        visited.append(False) +        vertex.append(0) +    dfs(G, 0, 0) +    for v in vertex: +        print(v)