#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ
N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

next_q = [(0, 0)]
while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2))
for i in color:
    print(i) 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) [] graph = [[] for _ in range(N)] graph [[] for _ in range(N)] color = [-1]*N color [-1]*N [-1] -1 N for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w)) i range(N-1) range N-1 N 1 a, b, w = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b w a -= 1 a 1 b -= 1 b 1 w %= 2 w 2 graph[a].append((b,w)) [a].append [a] graph a append (b,w) b w graph[b].append((a,w)) [b].append [b] graph b append (a,w) a w next_q = [(0, 0)] next_q [(0, 0)] (0, 0) 0 0 while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2)) len(next_q)>0 len(next_q) len next_q 0 nw, nc = next_q.pop() nw next_q.pop() next_q.pop next_q pop nc color[nw] = nc color[nw] color nw nc for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2)) nxt nl graph[nw] graph nw if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2)) color[nxt]==-1 color[nxt] color nxt -1 next_q.append((nxt,(nl+nc)%2)) next_q.append next_q append (nxt,(nl+nc)%2) nxt (nl+nc)%2 nl+nc nl nc 2 for i in color:
    print(i) i color print(i) print i N = int(input()) int(input()) N color = [-1]*N [-1]*N color graph = [[] for _ in range(N)] [[] for _ in range(N)] graph nw, nc = next_q.pop() next_q.pop() nw a -= 1 1 a w %= 2 2 w w = map(int, input().split()) map(int, input().split()) w b -= 1 1 b next_q = [(0, 0)] [(0, 0)] next_q a, b, w = map(int, input().split()) map(int, input().split()) a b, w = map(int, input().split()) map(int, input().split()) b nc = next_q.pop() next_q.pop() nc
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ
N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

next_q = [(0, 0)]
while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2))
for i in color:
    print(i)