Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
queue = [[root, 0]]
counter = -1
while -1 in answer:
    counter += 1
    node = queue[counter][0]
    depth = queue[counter][1]
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            queue.append([n, depth + graph[node][n]])

for a in answer:
   print('0' if a % 2 else '1')

Fixed submission:
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
queue = [[root, 0]]
counter = -1
while counter < N - 1:
    counter += 1
    node = queue[counter][0]
    depth = queue[counter][1]
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            queue.append([n, depth + graph[node][n]])

for a in answer:
   print('0' if a % 2 else '1')

Buggy python submission (verdict: Runtime Error):
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
def search(node, depth):
    answer[node] = depth
    for n in graph.get(node, {}):
        if answer[n] == -1:
            search(n,depth + graph[node][n])
if N == 1:
    print('0')
else:
    search(root, 0)
    for a in answer:
        print('0' if a % 2 else '1')

Fixed submission:
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
queue = [[root, 0]]
counter = -1
while counter < N - 1:
    counter += 1
    node = queue[counter][0]
    depth = queue[counter][1]
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            queue.append([n, depth + graph[node][n]])

for a in answer:
   print('0' if a % 2 else '1')

Buggy python submission (verdict: Runtime Error):
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
def search(node, depth):
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            search(n,depth + graph[node][n])
if N == 1:
    print('0')
else:
    search(root, 0)
    for a in answer:
        print('0' if a % 2 else '1')

Fixed submission:
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
queue = [[root, 0]]
counter = -1
while counter < N - 1:
    counter += 1
    node = queue[counter][0]
    depth = queue[counter][1]
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            queue.append([n, depth + graph[node][n]])

for a in answer:
   print('0' if a % 2 else '1')

Buggy python submission (verdict: Runtime Error):
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
def search(node, depth):
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            search(n,depth + graph[node][n])

search(root, 0)
for a in answer:
    print('0' if a % 2 else '1')

Fixed submission:
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
queue = [[root, 0]]
counter = -1
while counter < N - 1:
    counter += 1
    node = queue[counter][0]
    depth = queue[counter][1]
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            queue.append([n, depth + graph[node][n]])

for a in answer:
   print('0' if a % 2 else '1')

Buggy python submission (verdict: Runtime Error):
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

print(graph)

answer = [-1] * N
def search(node, depth):
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            search(n,depth + graph[node][n])

search(root, 0)
for a in answer:
    print('0' if a % 2 else '1')

Fixed submission:
N = int(input())
graph = {}
root = -1
for n in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1

    if root == -1:
        root = u
    if u not in graph:
        graph[u] = {}
    if v not in graph:
        graph[v] = {}
    graph[u][v] = w
    graph[v][u] = w    

answer = [-1] * N
queue = [[root, 0]]
counter = -1
while counter < N - 1:
    counter += 1
    node = queue[counter][0]
    depth = queue[counter][1]
    answer[node] = depth
    for n in graph[node]:
        if answer[n] == -1:
            queue.append([n, depth + graph[node][n]])

for a in answer:
   print('0' if a % 2 else '1')