import numpy as np





def read():

    N = int(input().strip())  # N <= 10**5

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

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

    for i in range(N-1):

        # u[i] < v[i] は保証されている

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

        to[u-1].append(v-1)

        to[v-1].append(u-1)

        cost[u-1].append(w % 2)

        cost[v-1].append(w % 2)

    return N, to, cost





def solve(N, to, cost):

    c = [-1] * N  # -1: unvisited, 0: white, 1: black

    q = list()

    c[0] = 0

    q.append(0)

    while len(q) > 0:

        s = q.pop()

        for t, co in zip(to[s], cost[s]):

            if c[t] == -1:

                if co:

                    c[t] = 1 - c[s]

                else:

                    c[t] = c[s]

                q.append(t)

    return c





if __name__ == '__main__':

    inputs = read()

    colors = solve(*inputs)

    for col in colors:

        print(("%d" % col))

import numpy as np





def read():

    N = int(input().strip())  # N <= 10**5

    edges = dict()

    for i in range(N-1):

        # u[i] < v[i] は保証されている

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

        if u - 1 in list(edges.keys()):

            edges[u - 1].update({v - 1: w % 2})

        else:

            edges.update({u - 1: {v - 1: w % 2}})

        if v - 1 in list(edges.keys()):

            edges[v - 1].update({u - 1: w % 2})

        else:

            edges.update({v - 1: {u - 1: w % 2}})

    return N, edges





def solve(N, edges):

    c = [-1] * N  # -1: unvisited, 0: white, 1: black

    stack = list()

    c[0] = 0

    stack.append(0)

    while len(stack) > 0:

        s = stack.pop()

        for t in list(edges[s].keys()):

            if c[t] == -1:

                if edges[s][t]:

                    c[t] = 1 - c[s]

                else:

                    c[t] = c[s]

                stack.append(t)

    return c





if __name__ == '__main__':

    inputs = read()

    colors = solve(*inputs)

    for col in colors:

        print(("%d" % col))

import numpy as np


def read():
    N = int(input().strip())  # N <= 10**5
    to = [[] for _ in range(N)]
    cost = [[] for _ in range(N)]
    for i in range(N - 1):
        # u[i] < v[i] は保証されている
        u, v, w = list(map(int, input().strip().split()))
        to[u - 1].append(v - 1)
        to[v - 1].append(u - 1)
        cost[u - 1].append(w % 2)
        cost[v - 1].append(w % 2)
    return N, to, cost


def solve(N, to, cost):
    c = [-1] * N  # -1: unvisited, 0: white, 1: black
    q = list()
    c[0] = 0
    q.append(0)
    while len(q) > 0:
        s = q.pop()
        for t, co in zip(to[s], cost[s]):
            if c[t] == -1:
                if co:
                    c[t] = 1 - c[s]
                else:
                    c[t] = c[s]
                q.append(t)
    return c


if __name__ == "__main__":
    inputs = read()
    colors = solve(*inputs)
    for col in colors:
        print(("%d" % col))

import numpy as np


def read():
    N = int(input().strip())  # N <= 10**5
    edges = dict()
    for i in range(N - 1):
        # u[i] < v[i] は保証されている
        u, v, w = list(map(int, input().strip().split()))
        if u - 1 in list(edges.keys()):
            edges[u - 1].update({v - 1: w % 2})
        else:
            edges.update({u - 1: {v - 1: w % 2}})
        if v - 1 in list(edges.keys()):
            edges[v - 1].update({u - 1: w % 2})
        else:
            edges.update({v - 1: {u - 1: w % 2}})
    return N, edges


def solve(N, edges):
    c = [-1] * N  # -1: unvisited, 0: white, 1: black
    stack = list()
    c[0] = 0
    stack.append(0)
    while len(stack) > 0:
        s = stack.pop()
        for t in list(edges[s].keys()):
            if c[t] == -1:
                if edges[s][t]:
                    c[t] = 1 - c[s]
                else:
                    c[t] = c[s]
                stack.append(t)
    return c


if __name__ == "__main__":
    inputs = read()
    colors = solve(*inputs)
    for col in colors:
        print(("%d" % col))

-    to = [[] for _ in range(N)] -    cost = [[] for _ in range(N)] +    edges = dict() -        to[u - 1].append(v - 1) -        to[v - 1].append(u - 1) -        cost[u - 1].append(w % 2) -        cost[v - 1].append(w % 2) -    return N, to, cost +        if u - 1 in list(edges.keys()): +            edges[u - 1].update({v - 1: w % 2}) +        else: +            edges.update({u - 1: {v - 1: w % 2}}) +        if v - 1 in list(edges.keys()): +            edges[v - 1].update({u - 1: w % 2}) +        else: +            edges.update({v - 1: {u - 1: w % 2}}) +    return N, edges -def solve(N, to, cost): +def solve(N, edges): -    q = list() +    stack = list() -    q.append(0) -    while len(q) > 0: -        s = q.pop() -        for t, co in zip(to[s], cost[s]): +    stack.append(0) +    while len(stack) > 0: +        s = stack.pop() +        for t in list(edges[s].keys()): -                if co: +                if edges[s][t]: -                q.append(t) +                stack.append(t)