Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N = int(input())
W = [list(map(int, input().split())) for _ in range(N-1)]
nodes = [[] for _ in range(N+1)]
for w in W:
    nodes[w[0]].append((w[1], w[2]))
    nodes[w[1]].append((w[0], w[2]))
ans = [-1] * (N+1)
ans[1] = 0
def search(num, root, dis):
    for node in nodes[num]:
        sum_d = dis
        if node[0] != root:
            idx = node[0]
            sum_d += node[1]%2
            if sum_d%2 != 0:
                ans[idx] = 1
            else:
                ans[idx] = 0
            search(idx, num, sum_d)

search(1, 0, 0)
for answer in ans[1:]:
    print(answer)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20000)

N = int(input())
W = [list(map(int, input().split())) for _ in range(N-1)]
nodes = [[] for _ in range(N+1)]
for w in W:
    nodes[w[0]].append((w[1], w[2]))
    nodes[w[1]].append((w[0], w[2]))
ans = [-1] * (N+1)
ans[1] = 0
def search(num, root, dis):
    for node in nodes[num]:
        sum_d = dis
        if node[0] != root:
            idx = node[0]
            sum_d += node[1]%2
            if sum_d%2 != 0:
                ans[idx] = 1
            else:
                ans[idx] = 0
            search(idx, num, sum_d)

search(1, 0, 0)
for answer in ans[1:]:
    print(answer)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

N = int(input())
W = [list(map(int, input().split())) for _ in range(N-1)]
nodes = [[] for _ in range(N+1)]
for w in W:
    nodes[w[0]].append((w[1], w[2]))
    nodes[w[1]].append((w[0], w[2]))
ans = [-1] * (N+1)
ans[1] = 0
def search(num, root, dis):
    for node in nodes[num]:
        sum_d = dis
        if node[0] != root:
            idx = node[0]
            sum_d += node[1]%2
            if sum_d%2 != 0:
                ans[idx] = 1
            else:
                ans[idx] = 0
            search(idx, num, sum_d)

search(1, 0, 0)
for answer in ans[1:]:
    print(answer)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(5000)

N = int(input())
W = [list(map(int, input().split())) for _ in range(N-1)]
nodes = [[] for _ in range(N+1)]
for w in W:
    nodes[w[0]].append((w[1], w[2]))
    nodes[w[1]].append((w[0], w[2]))
ans = [-1] * (N+1)
ans[1] = 0
def search(num, root, dis):
    for node in nodes[num]:
        if node[0] != root:
            idx = node[0]
            dis += node[1]%2
            if dis%2 != 0:
                ans[idx] = 1
            else:
                ans[idx] = 0
            search(idx, num, dis)

search(1, 0, 0)
for answer in ans[1:]:
    print(answer)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(5000)

N = int(input())
W = [list(map(int, input().split())) for _ in range(N-1)]
nodes = [[] for _ in range(N+1)]
for w in W:
    nodes[w[0]].append((w[1], w[2]))
    nodes[w[1]].append((w[0], w[2]))
ans = [0] * (N+1)
def search(num, root, dis):
    for node in nodes[num]:
        if node[0] != root:
            idx = node[0]
            dis += node[1]%2
            if dis%2 != 0:
                ans[idx] = 1
            search(idx, num, dis)

search(1, 0, 0)
for answer in ans[1:]:
    print(answer)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(5000)

N = int(input())
W = [list(map(int, input().split())) for _ in range(N-1)]
len_w = N-1
ans = [0] * (N+1)
def search(num, root, dis):
    # nodes = tuple(filter(lambda x:x[0] == num or x[1] == num, W))
    nodes = []
    global len_w
    for i in range(len_w):
        if i == len_w:
            break
        if W[i][0] == num or W[i][1] == num:
            nodes.append(W[i])
            del W[i]
            len_w -= 1
    for node in nodes:
        if node[0] != root and node[1] != root:
            idx = node[1] if node[0] == num else node[0]
            dis += node[2]%2
            if dis%2 != 0:
                ans[idx] = 1
            search(idx, num, dis)
        # else:
        #     dis += node[2]%2
        #     if dis%2 != 0:
        #         idx = node[1] if node[0] == num else node[0]
        #         ans[idx] = 1

search(1, 0, 0)
for answer in ans[1:]:
    print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [list(map(int, input().split())) for i in range(N-1)]

A = [0] * (N)
L.sort()
for i in L:
    if i[2]%2 != 0 and L[i[0]] == L[i[1]]:
        L[i[0]] = (L[i[0]]+1)%2
    elif i[2]%2 == 0:
        L[i[1]] = L[i[0]]
for i in A:
    print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [list(map(int, input().split())) for i in range(N-1)]

A = [0] * (N)
L.sort()
for i in L:
    if i[2]%2 != 0 and L[i[0]] == L[i[1]]:
        L[i[0]] = !L[i[0]]
    elif i[2]%2 == 0:
        L[i[1]] = L[i[0]]
for i in A:
    print(i)