import sys
from collections import deque

input = sys.stdin.readline


def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        G[u].append((v, w))
        G[v].append((u, w))

    ans = [-1] * N
    ans[0] = 0
    stack = deque([(-1, 0)])
    while stack:
        p, u = stack.pop()
        for v, w in G[u]:
            if v == p:
                continue
            if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
            stack.append((u, v))

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main() import sys sys from collections import deque input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        G[u].append((v, w))
        G[v].append((u, w))

    ans = [-1] * N
    ans[0] = 0
    stack = deque([(-1, 0)])
    while stack:
        p, u = stack.pop()
        for v, w in G[u]:
            if v == p:
                continue
            if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
            stack.append((u, v))

    print("\n".join(map(str, ans))) main N = int(input()) N int(input()) int input() input [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] G = [[] for _ in range(N)] G [[] for _ in range(N)] for i in range(N - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        G[u].append((v, w))
        G[v].append((u, w))

     i range(N - 1) range N - 1 N 1 u, v, w = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split v w u -= 1 u 1 v -= 1 v 1 G[u].append((v, w)) [u].append [u] G u append (v, w) v w G[v].append((u, w)) [v].append [v] G v append (u, w) u w ans = [-1] * N ans [-1] * N [-1] -1 N ans[0] = 0 ans[0] ans 0 0 stack = deque([(-1, 0)]) stack deque([(-1, 0)]) deque [(-1, 0)] (-1, 0) -1 0 while stack:
        p, u = stack.pop()
        for v, w in G[u]:
            if v == p:
                continue
            if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
            stack.append((u, v))

     stack p, u = stack.pop() p stack.pop() stack.pop stack pop u for v, w in G[u]:
            if v == p:
                continue
            if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
            stack.append((u, v))

     v w G[u] G u if v == p:
                continue
             v == p v p continue if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
             w % 2 == 0 w % 2 w 2 0 ans[v] = ans[u] ans[v] ans v ans[u] ans u ans[v] = (ans[u] + 1) % 2 ans[v] ans v (ans[u] + 1) % 2 ans[u] + 1 ans[u] ans u 1 2 stack.append((u, v)) stack.append stack append (u, v) u v print("\n".join(map(str, ans))) print "\n".join(map(str, ans)) "\n".join "\n" join map(str, ans) map str ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        G[u].append((v, w))
        G[v].append((u, w))

    ans = [-1] * N
    ans[0] = 0
    stack = deque([(-1, 0)])
    while stack:
        p, u = stack.pop()
        for v, w in G[u]:
            if v == p:
                continue
            if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
            stack.append((u, v))

    print("\n".join(map(str, ans))) def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        G[u].append((v, w))
        G[v].append((u, w))

    ans = [-1] * N
    ans[0] = 0
    stack = deque([(-1, 0)])
    while stack:
        p, u = stack.pop()
        for v, w in G[u]:
            if v == p:
                continue
            if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
            stack.append((u, v))

    print("\n".join(map(str, ans))) main input = sys.stdin.readline sys.stdin.readline input
import sys
from collections import deque

input = sys.stdin.readline


def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        G[u].append((v, w))
        G[v].append((u, w))

    ans = [-1] * N
    ans[0] = 0
    stack = deque([(-1, 0)])
    while stack:
        p, u = stack.pop()
        for v, w in G[u]:
            if v == p:
                continue
            if w % 2 == 0:
                ans[v] = ans[u]
            else:
                ans[v] = (ans[u] + 1) % 2
            stack.append((u, v))

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()
