# ABC126D - Even Relation

def dfs(r: int) -> None:

    stack = [r]

    while stack:

        v = stack.pop()

        for u, w in T[v]:

            if D[u] == -1:

                D[u] = (D[v] + w) % 2

                stack += [u]





def main():

    global T, D

    N, *A = map(int, open(0).read().split())

    T = [[] for _ in range(N + 1)]

    for i in range(0, (N - 1) * 3, 3):

        v, u, w = A[i : i + 3]

        T[v] += [(u, w)]

        T[u] += [(v, w)]

    D = [-1] * (N + 1)  # D[i] := parity of distance from vertex 1 (root)

    D[1] = 0

    dfs(1)

    print(*D[1:], sep="\n")





if __name__ == "__main__":

    main()

# D - Even Relation

from typing import List, Tuple





def main():

    N, *X = list(map(int, open(0).read().split()))

    tree: List[List[Tuple[int, int]]] = [[] for _ in range(N + 1)]

    for u, v, w in zip(*[iter(X)] * 3):

        w %= 2

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



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

    color[1] = 1

    stack = [1]

    while stack:

        u = stack.pop()

        cur = color[u]

        for v, w in tree[u]:

            if color[v] != -1:

                continue

            color[v] = cur ^ w

            stack.append(v)



    print(("\n".join(map(str, color[1:]))))





if __name__ == "__main__":

    main()

# ABC126D - Even Relation
def dfs(r: int) -> None:
    stack = [r]
    while stack:
        v = stack.pop()
        for u, w in T[v]:
            if D[u] == -1:
                D[u] = (D[v] + w) % 2
                stack += [u]


def main():
    global T, D
    N, *A = map(int, open(0).read().split())
    T = [[] for _ in range(N + 1)]
    for i in range(0, (N - 1) * 3, 3):
        v, u, w = A[i : i + 3]
        T[v] += [(u, w)]
        T[u] += [(v, w)]
    D = [-1] * (N + 1)  # D[i] := parity of distance from vertex 1 (root)
    D[1] = 0
    dfs(1)
    print(*D[1:], sep="\n")


if __name__ == "__main__":
    main()

# D - Even Relation
from typing import List, Tuple


def main():
    N, *X = list(map(int, open(0).read().split()))
    tree: List[List[Tuple[int, int]]] = [[] for _ in range(N + 1)]
    for u, v, w in zip(*[iter(X)] * 3):
        w %= 2
        tree[u].append((v, w)), tree[v].append((u, w))
    color = [-1] * (N + 1)
    color[1] = 1
    stack = [1]
    while stack:
        u = stack.pop()
        cur = color[u]
        for v, w in tree[u]:
            if color[v] != -1:
                continue
            color[v] = cur ^ w
            stack.append(v)
    print(("\n".join(map(str, color[1:]))))


if __name__ == "__main__":
    main()

-# ABC126D - Even Relation -def dfs(r: int) -> None: -    stack = [r] -    while stack: -        v = stack.pop() -        for u, w in T[v]: -            if D[u] == -1: -                D[u] = (D[v] + w) % 2 -                stack += [u] +# D - Even Relation +from typing import List, Tuple -    global T, D -    N, *A = map(int, open(0).read().split()) -    T = [[] for _ in range(N + 1)] -    for i in range(0, (N - 1) * 3, 3): -        v, u, w = A[i : i + 3] -        T[v] += [(u, w)] -        T[u] += [(v, w)] -    D = [-1] * (N + 1)  # D[i] := parity of distance from vertex 1 (root) -    D[1] = 0 -    dfs(1) -    print(*D[1:], sep="\n") +    N, *X = list(map(int, open(0).read().split())) +    tree: List[List[Tuple[int, int]]] = [[] for _ in range(N + 1)] +    for u, v, w in zip(*[iter(X)] * 3): +        w %= 2 +        tree[u].append((v, w)), tree[v].append((u, w)) +    color = [-1] * (N + 1) +    color[1] = 1 +    stack = [1] +    while stack: +        u = stack.pop() +        cur = color[u] +        for v, w in tree[u]: +            if color[v] != -1: +                continue +            color[v] = cur ^ w +            stack.append(v) +    print(("\n".join(map(str, color[1:]))))