import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
graph = [0] + [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u].append((v, w))
    graph[v].append((u, w))

def dfs(graph, queue, color):
    is_bigraph = True
    while queue:
        current = queue.pop()
        current_color = color[current]

        for _next, dist in graph[current]:
            if color[_next] != - 1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)

    return is_bigraph

queue = [1]
color = [-1] + [-1] * n
color[1] = 0
if not dfs(graph, queue, color):
    print('Something wrong')
    sys.exit(1)

for c in color[1:]:
    print(c) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 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 = [0] + [[] for _ in range(n)] graph [0] + [[] for _ in range(n)] [0] 0 [[] for _ in range(n)] for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u].append((v, w))
    graph[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 graph[u].append((v, w)) [u].append [u] graph u append (v, w) v w graph[v].append((u, w)) [v].append [v] graph v append (u, w) u w def dfs(graph, queue, color):
    is_bigraph = True
    while queue:
        current = queue.pop()
        current_color = color[current]

        for _next, dist in graph[current]:
            if color[_next] != - 1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)

    return is_bigraph dfs is_bigraph = True is_bigraph True while queue:
        current = queue.pop()
        current_color = color[current]

        for _next, dist in graph[current]:
            if color[_next] != - 1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)

     queue current = queue.pop() current queue.pop() queue.pop queue pop current_color = color[current] current_color color[current] color current for _next, dist in graph[current]:
            if color[_next] != - 1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)

     _next dist graph[current] graph current if color[_next] != - 1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)

     color[_next] != - 1 color[_next] color _next - 1 if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
             color[_next] != (color[current] + dist) % 2 color[_next] color _next (color[current] + dist) % 2 color[current] + dist color[current] color current dist 2 is_bigraph = False is_bigraph False color[_next] = (color[current] + dist) % 2 color[_next] color _next (color[current] + dist) % 2 color[current] + dist color[current] color current dist 2 queue.append(_next) queue.append queue append _next return is_bigraph is_bigraph graph graph queue queue color color queue = [1] queue [1] 1 color = [-1] + [-1] * n color [-1] + [-1] * n [-1] -1 [-1] * n [-1] -1 n color[1] = 0 color[1] color 1 0 if not dfs(graph, queue, color):
    print('Something wrong')
    sys.exit(1) not dfs(graph, queue, color) dfs(graph, queue, color) dfs graph queue color print('Something wrong') print 'Something wrong' sys.exit(1) sys.exit sys exit 1 for c in color[1:]:
    print(c) c color[1:] color 1: 1 print(c) print c v, w = map(int, input().split()) map(int, input().split()) v input = sys.stdin.readline sys.stdin.readline input n = int(input()) int(input()) n graph = [0] + [[] for _ in range(n)] [0] + [[] for _ in range(n)] graph queue = [1] [1] queue u, v, w = map(int, input().split()) map(int, input().split()) u color = [-1] + [-1] * n [-1] + [-1] * n color w = map(int, input().split()) map(int, input().split()) w def dfs(graph, queue, color):
    is_bigraph = True
    while queue:
        current = queue.pop()
        current_color = color[current]

        for _next, dist in graph[current]:
            if color[_next] != - 1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)

    return is_bigraph def dfs(graph, queue, color):
    is_bigraph = True
    while queue:
        current = queue.pop()
        current_color = color[current]

        for _next, dist in graph[current]:
            if color[_next] != - 1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)

    return is_bigraph dfs
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
graph = [0] + [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u].append((v, w))
    graph[v].append((u, w))

def dfs(graph, queue, color):
    is_bigraph = True
    while queue:
        current = queue.pop()
        current_color = color[current]

        for _next, dist in graph[current]:
            if color[_next] != - 1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)

    return is_bigraph

queue = [1]
color = [-1] + [-1] * n
color[1] = 0
if not dfs(graph, queue, color):
    print('Something wrong')
    sys.exit(1)

for c in color[1:]:
    print(c)
