# D - Even Relation
from typing import List, Tuple


def main():
    N, *X = 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() from typing import List, Tuple def main():
    N, *X = 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:]))) main N, *X = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split *X X [] for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [] tree: List[List[Tuple[int, int]]] = [[] for _ in range(N + 1)] tree [[] 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))

     u v w zip(*[iter(X)] * 3) zip *[iter(X)] * 3 [iter(X)] * 3 [iter(X)] iter(X) iter X 3 w %= 2 w 2 tree[u].append((v, w)) [u].append [u] tree u append (v, w) v w tree[v].append((u, w)) [v].append [v] tree v append (u, w) u w color = [-1] * (N + 1) color [-1] * (N + 1) [-1] -1 N + 1 N 1 color[1] = 1 color[1] color 1 1 stack = [1] stack [1] 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)

     stack u = stack.pop() u stack.pop() stack.pop stack pop cur = color[u] cur color[u] color u for v, w in tree[u]:
            if color[v] != -1:
                continue
            color[v] = cur ^ w
            stack.append(v)

     v w tree[u] tree u if color[v] != -1:
                continue
             color[v] != -1 color[v] color v -1 continue color[v] = cur ^ w color[v] color v cur ^ w cur w stack.append(v) stack.append stack append v print("\n".join(map(str, color[1:]))) print "\n".join(map(str, color[1:])) "\n".join "\n" join map(str, color[1:]) map str color[1:] color 1: 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, *X = 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:]))) def main():
    N, *X = 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:]))) main
# D - Even Relation
from typing import List, Tuple


def main():
    N, *X = 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()
