Buggy python submission (verdict: Runtime Error):
import heapq as hp
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [[] for i in range(N)]
for u,v,w in arr:
    e_list[u].add([v,w])
    e_list[v].add([u,w])

stack = [0]
ans[0] = 0
for rnd in range(N):
    if stack == []:
        break
    cur_pos = stack.pop()
    for des in e_list[cur_pos]:
        if ans[des] >  0:
            continue
        ans[des] = ans[cur_pos] + e_list[des][cur_pos]
        stack.append(des)
for i in ans:
    print(i)

Fixed submission:
import heapq as hp
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [[] for i in range(N)]
for u,v,w in arr:
    e_list[u].append([v,w])
    e_list[v].append([u,w])

stack = [0]
ans[0] = 0
while(stack):
    cur_pos = stack.pop()
    for des,cost in e_list[cur_pos]:
        if ans[des] >=  0:
            continue
        ans[des] = (ans[cur_pos] + cost)%2
        stack.append(des)
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq as hp
N = int(input())
d = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [set() for i in range(N)]
e_graph = [[0]*N for i in range(N)]
for u,v,w in arr:
    e_list[u].add(v)
    e_list[v].add(u)
    e_graph[u][v] = w
    e_graph[v][u] = w

stack = [[0,0]]
d[0] = 0
for w in range(N):
    if stack == []:
        break
    cost,cur_pos = hp.heappop(stack)
    cost *= -1
    for des in e_list[cur_pos]:
        if d[des] < 0:
            d[des] = d[cur_pos] + e_graph[cur_pos][des]
            hp.heappush(stack,[-d[des],des])

for i in d:
    print(i%2)


Fixed submission:
import heapq as hp
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [[] for i in range(N)]
for u,v,w in arr:
    e_list[u].append([v,w])
    e_list[v].append([u,w])

stack = [0]
ans[0] = 0
while(stack):
    cur_pos = stack.pop()
    for des,cost in e_list[cur_pos]:
        if ans[des] >=  0:
            continue
        ans[des] = (ans[cur_pos] + cost)%2
        stack.append(des)
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [set() for i in range(N)]
e_graph = [[0]*N for i in range(N)]
for u,v,w in arr:
    e_list[u].add(v)
    e_list[v].add(u)
    e_graph[u][v] = w
    e_graph[v][u] = w

stack = [0]
ans[0] = 0
for rnd in range(N):
    if stack == []:
        break
    cur_pos = stack.pop()
    for des in e_list[cur_pos]:
        if ans[des] < 0:
            if e_graph[cur_pos][des] %2 == 0:
                ans[des] = ans[cur_pos]
            else:
                ans[des] = (ans[cur_pos] + 1)%2
            e_list[des].remove(cur_pos)
            stack.append(des)
for i in ans:
    print(i)

Fixed submission:
import heapq as hp
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [[] for i in range(N)]
for u,v,w in arr:
    e_list[u].append([v,w])
    e_list[v].append([u,w])

stack = [0]
ans[0] = 0
while(stack):
    cur_pos = stack.pop()
    for des,cost in e_list[cur_pos]:
        if ans[des] >=  0:
            continue
        ans[des] = (ans[cur_pos] + cost)%2
        stack.append(des)
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [[] for i in range(N)]
e_graph = [[0]*N for i in range(N)]
for u,v,w in arr:
    e_list[u].append(v)
    e_list[v].append(u)
    e_graph[u][v] = w
    e_graph[v][u] = w

stack = [0]
ans[0] = 0
while (stack):
    cur_pos = stack.pop()
    for des in e_list[cur_pos]:
        t = ans[des]
        if ans[des] < 0:
            if e_graph[cur_pos][des] %2 == 0:
                ans[des] = ans[cur_pos]
            else:
                ans[des] = (ans[cur_pos] + 1)%2
            stack.append(des)
for i in ans:
    print(i)

Fixed submission:
import heapq as hp
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [[] for i in range(N)]
for u,v,w in arr:
    e_list[u].append([v,w])
    e_list[v].append([u,w])

stack = [0]
ans[0] = 0
while(stack):
    cur_pos = stack.pop()
    for des,cost in e_list[cur_pos]:
        if ans[des] >=  0:
            continue
        ans[des] = (ans[cur_pos] + cost)%2
        stack.append(des)
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [[] for i in range(N)]
e_graph = [[0]*N for i in range(N)]
for u,v,w in arr:
    e_list[u].append(v)
    e_list[v].append(u)
    e_graph[u][v] = w
    e_graph[v][u] = w

stack = [0]
ans[0] = 0
while (stack):
    cur_pos = stack.pop()
    for des in e_list[cur_pos]:
        t = ans[des]
        if ans[des] < 0:
            if e_graph[cur_pos][des] %2 == 0:
                ans[des] = ans[cur_pos]
            else:
                ans[des] = (ans[cur_pos] + 1)%2
            stack.append(des)
for i in ans:
    print(i)

Fixed submission:
import heapq as hp
N = int(input())
ans = [-1]*N
arr = []
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    arr.append([u,v,w])
e_list = [[] for i in range(N)]
for u,v,w in arr:
    e_list[u].append([v,w])
    e_list[v].append([u,w])

stack = [0]
ans[0] = 0
while(stack):
    cur_pos = stack.pop()
    for des,cost in e_list[cur_pos]:
        if ans[des] >=  0:
            continue
        ans[des] = (ans[cur_pos] + cost)%2
        stack.append(des)
for i in ans:
    print(i)