# 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()

# ABC126D - Even Relation

def main():

    # same parity of distance from root <-> same group

    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

    stack = [1]  # dfs starting from root

    while stack:

        v = stack.pop()

        for u, w in T[v]:

            if D[u] == -1:

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

                stack.append(u)

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





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()

# ABC126D - Even Relation
def main():
    # same parity of distance from root <-> same group
    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
    stack = [1]  # dfs starting from root
    while stack:
        v = stack.pop()
        for u, w in T[v]:
            if D[u] == -1:
                D[u] = (D[v] + w) % 2
                stack.append(u)
    print(*D[1:], sep="\n")


if __name__ == "__main__":
    main()

-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] - - +    # same parity of distance from root <-> same group -    dfs(1) +    stack = [1]  # dfs starting from root +    while stack: +        v = stack.pop() +        for u, w in T[v]: +            if D[u] == -1: +                D[u] = (D[v] + w) % 2 +                stack.append(u)