def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = (int(i) for i in input().split())
        G[a-1].append((b-1, c % 2))
        G[b-1].append((a-1, c % 2))

    color = [-1]*N

    def dfs(s):
        seen = [False]*N
        stack = [s]
        seen[s] = True
        color[0] = 0
        while stack:
            v = stack.pop()
            for u, dist in G[v]:
                if seen[u]:
                    continue
                if dist == 1:
                    color[u] = color[v] ^ 1
                else:
                    color[u] = color[v]
                stack.append(u)
                seen[u] = True

    dfs(0)
    print(*color, sep="\n")


if __name__ == '__main__':
    main() def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = (int(i) for i in input().split())
        G[a-1].append((b-1, c % 2))
        G[b-1].append((a-1, c % 2))

    color = [-1]*N

    def dfs(s):
        seen = [False]*N
        stack = [s]
        seen[s] = True
        color[0] = 0
        while stack:
            v = stack.pop()
            for u, dist in G[v]:
                if seen[u]:
                    continue
                if dist == 1:
                    color[u] = color[v] ^ 1
                else:
                    color[u] = color[v]
                stack.append(u)
                seen[u] = True

    dfs(0)
    print(*color, sep="\n") 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 _ in range(N-1):
        a, b, c = (int(i) for i in input().split())
        G[a-1].append((b-1, c % 2))
        G[b-1].append((a-1, c % 2))

     _ range(N-1) range N-1 N 1 int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a, b, c = (int(i) for i in input().split()) a (int(i) for i in input().split()) b c G[a-1].append((b-1, c % 2)) [a-1].append [a-1] G a-1 a 1 append (b-1, c % 2) b-1 b 1 c % 2 c 2 G[b-1].append((a-1, c % 2)) [b-1].append [b-1] G b-1 b 1 append (a-1, c % 2) a-1 a 1 c % 2 c 2 color = [-1]*N color [-1]*N [-1] -1 N def dfs(s):
        seen = [False]*N
        stack = [s]
        seen[s] = True
        color[0] = 0
        while stack:
            v = stack.pop()
            for u, dist in G[v]:
                if seen[u]:
                    continue
                if dist == 1:
                    color[u] = color[v] ^ 1
                else:
                    color[u] = color[v]
                stack.append(u)
                seen[u] = True

     dfs seen = [False]*N seen [False]*N [False] False N stack = [s] stack [s] s seen[s] = True seen[s] seen s True color[0] = 0 color[0] color 0 0 while stack:
            v = stack.pop()
            for u, dist in G[v]:
                if seen[u]:
                    continue
                if dist == 1:
                    color[u] = color[v] ^ 1
                else:
                    color[u] = color[v]
                stack.append(u)
                seen[u] = True

     stack v = stack.pop() v stack.pop() stack.pop stack pop for u, dist in G[v]:
                if seen[u]:
                    continue
                if dist == 1:
                    color[u] = color[v] ^ 1
                else:
                    color[u] = color[v]
                stack.append(u)
                seen[u] = True

     u dist G[v] G v if seen[u]:
                    continue
                 seen[u] seen u continue if dist == 1:
                    color[u] = color[v] ^ 1
                else:
                    color[u] = color[v]
                 dist == 1 dist 1 color[u] = color[v] ^ 1 color[u] color u color[v] ^ 1 color[v] color v 1 color[u] = color[v] color[u] color u color[v] color v stack.append(u) stack.append stack append u seen[u] = True seen[u] seen u True s s dfs(0) dfs 0 print(*color, sep="\n") print *color color sep="\n" sep "\n" if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = (int(i) for i in input().split())
        G[a-1].append((b-1, c % 2))
        G[b-1].append((a-1, c % 2))

    color = [-1]*N

    def dfs(s):
        seen = [False]*N
        stack = [s]
        seen[s] = True
        color[0] = 0
        while stack:
            v = stack.pop()
            for u, dist in G[v]:
                if seen[u]:
                    continue
                if dist == 1:
                    color[u] = color[v] ^ 1
                else:
                    color[u] = color[v]
                stack.append(u)
                seen[u] = True

    dfs(0)
    print(*color, sep="\n") def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = (int(i) for i in input().split())
        G[a-1].append((b-1, c % 2))
        G[b-1].append((a-1, c % 2))

    color = [-1]*N

    def dfs(s):
        seen = [False]*N
        stack = [s]
        seen[s] = True
        color[0] = 0
        while stack:
            v = stack.pop()
            for u, dist in G[v]:
                if seen[u]:
                    continue
                if dist == 1:
                    color[u] = color[v] ^ 1
                else:
                    color[u] = color[v]
                stack.append(u)
                seen[u] = True

    dfs(0)
    print(*color, sep="\n") main
def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = (int(i) for i in input().split())
        G[a-1].append((b-1, c % 2))
        G[b-1].append((a-1, c % 2))

    color = [-1]*N

    def dfs(s):
        seen = [False]*N
        stack = [s]
        seen[s] = True
        color[0] = 0
        while stack:
            v = stack.pop()
            for u, dist in G[v]:
                if seen[u]:
                    continue
                if dist == 1:
                    color[u] = color[v] ^ 1
                else:
                    color[u] = color[v]
                stack.append(u)
                seen[u] = True

    dfs(0)
    print(*color, sep="\n")


if __name__ == '__main__':
    main()
