import sys

sys.setrecursionlimit(10**7)


def dfs(s, to, color):
    for next_v, step in to[s]:
        if color[next_v] == -1:
            if step % 2 == 0:
                color[next_v] = color[s]
            else:
                color[next_v] = color[s] ^ 1
            dfs(next_v, to, color)


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

    color = [-1] * N #-1: 未探索、0: 白、1: 黒
    color[0] = 0
    dfs(0, to, color)
    print(*color, sep='\n')


if __name__ == "__main__":
    solve() import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def dfs(s, to, color):
    for next_v, step in to[s]:
        if color[next_v] == -1:
            if step % 2 == 0:
                color[next_v] = color[s]
            else:
                color[next_v] = color[s] ^ 1
            dfs(next_v, to, color) dfs for next_v, step in to[s]:
        if color[next_v] == -1:
            if step % 2 == 0:
                color[next_v] = color[s]
            else:
                color[next_v] = color[s] ^ 1
            dfs(next_v, to, color) next_v step to[s] to s if color[next_v] == -1:
            if step % 2 == 0:
                color[next_v] = color[s]
            else:
                color[next_v] = color[s] ^ 1
            dfs(next_v, to, color) color[next_v] == -1 color[next_v] color next_v -1 if step % 2 == 0:
                color[next_v] = color[s]
            else:
                color[next_v] = color[s] ^ 1
             step % 2 == 0 step % 2 step 2 0 color[next_v] = color[s] color[next_v] color next_v color[s] color s color[next_v] = color[s] ^ 1 color[next_v] color next_v color[s] ^ 1 color[s] color s 1 dfs(next_v, to, color) dfs next_v to color s s to to color color def solve():
    N = int(input())
    to = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        u, v = u - 1, v - 1
        to[u].append([v, w])
        to[v].append([u, w])

    color = [-1] * N #-1: 未探索、0: 白、1: 黒
    color[0] = 0
    dfs(0, to, color)
    print(*color, sep='\n') solve 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) [] to = [[] for _ in range(N)] to [[] for _ in range(N)] for _ in range(N - 1):
        u, v, w = map(int, input().split())
        u, v = u - 1, v - 1
        to[u].append([v, w])
        to[v].append([u, w])

     _ 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, v = u - 1, v - 1 u u - 1 u 1 v v - 1 v 1 to[u].append([v, w]) [u].append [u] to u append [v, w] v w to[v].append([u, w]) [v].append [v] to v append [u, w] u w color = [-1] * N color [-1] * N [-1] -1 N color[0] = 0 color[0] color 0 0 dfs(0, to, color) dfs 0 to color print(*color, sep='\n') print *color color sep='\n' sep '\n' if __name__ == "__main__":
    solve() __name__ == "__main__" __name__ "__main__" solve() solve def dfs(s, to, color):
    for next_v, step in to[s]:
        if color[next_v] == -1:
            if step % 2 == 0:
                color[next_v] = color[s]
            else:
                color[next_v] = color[s] ^ 1
            dfs(next_v, to, color) def dfs(s, to, color):
    for next_v, step in to[s]:
        if color[next_v] == -1:
            if step % 2 == 0:
                color[next_v] = color[s]
            else:
                color[next_v] = color[s] ^ 1
            dfs(next_v, to, color) dfs def solve():
    N = int(input())
    to = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        u, v = u - 1, v - 1
        to[u].append([v, w])
        to[v].append([u, w])

    color = [-1] * N #-1: 未探索、0: 白、1: 黒
    color[0] = 0
    dfs(0, to, color)
    print(*color, sep='\n') def solve():
    N = int(input())
    to = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        u, v = u - 1, v - 1
        to[u].append([v, w])
        to[v].append([u, w])

    color = [-1] * N #-1: 未探索、0: 白、1: 黒
    color[0] = 0
    dfs(0, to, color)
    print(*color, sep='\n') solve
import sys

sys.setrecursionlimit(10**7)


def dfs(s, to, color):
    for next_v, step in to[s]:
        if color[next_v] == -1:
            if step % 2 == 0:
                color[next_v] = color[s]
            else:
                color[next_v] = color[s] ^ 1
            dfs(next_v, to, color)


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

    color = [-1] * N #-1: 未探索、0: 白、1: 黒
    color[0] = 0
    dfs(0, to, color)
    print(*color, sep='\n')


if __name__ == "__main__":
    solve()