Problem p02936 (python)

Fixed submission:
from collections import deque
n, q = map(int, input().split())
tree = [[] for _ in range(n+1)]
cnt = [0] * (n+1)

for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    cnt[p] += x

queue = deque([1])
visited = {1}
while queue:
    now = queue.popleft()
    visited.add(now)
    for t in tree[now]:
        if t in visited:
            pass
        else:
            queue.append(t)
            cnt[t] += cnt[now]

print(*cnt[1:])

Buggy submission (verdict: Runtime Error):
import numpy as np
n, q = map(int, input().split())
e = np.eye(n + 1, dtype=int)
point = np.zeros(n+1, dtype=int)
for i in range(n - 1):
    a, b = map(int, input().split())
    if a != 1 and sum(e[1:a, a]) == 0:
        e[b][a] = 1
    else:
        e[a][b] = 1

def calc(x, y):
    for i in range(y):
        for j in range(y):
            if x[i][j] >= 1:
                x[i][j] = 1

for i in range(q):
    p, x = map(int, input().split())
    point[p] += x

for i in range(1, n+1):
    for j in range(i+1,n+1):
        if e[i][j] == 1:
            e[i] += e[j]
        else:
            continue

calc(e[1:, 1:], n)
ans = np.dot(point[1:], e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, q = map(int, input().split())
e = np.eye(n + 1, dtype=int)
point = np.zeros(n+1, dtype=int)
for i in range(n - 1):
    a, b = map(int, input().split())
    e[a][b] = 1
for i in range(q):
    p, x = map(int, input().split())
    point[p] += x

for i in range(1, n):
    for j in range(i+1,n):
        if e[i][j] == 1:
            e[i][j+1:] += e[j][j+1:]
        else:
            continue
ans = np.dot(point[1:], e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n, q = map(int, input().split())

e = np.eye(n + 1, dtype=int)
for i in range(n - 1):
    a, b = map(int, input().split())
    e[a][b] = 1

for i in range(1, n):
    for j in range(i+1,n):
        if e[i][j] == 1:
            e[i][j+1:] += e[j][j + 1:]
        else:
            continue

point = np.zeros(n, dtype=int)
for i in range(q):
    p, x = map(int, input().split())
    point[p - 1] += x
ans = np.dot(point, e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n, q = map(int, input().split())

e = np.eye(n + 1, dtype=int)
for i in range(n - 1):
    a, b = map(int, input().split())
    e[a][b] = 1

for i in reversed(range(2, n)):
    for j in range(1, i):
        if e[i - j][i] == 1:
            e[i - j][i + 1:] += e[i][i + 1:]
        else:
            continue

point = np.zeros(n, dtype=int)
for i in range(q):
    p, x = map(int, input().split())
    point[p - 1] += x
print(e[1:, 1:])
ans = np.dot(point, e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, q = map(int, input().split())

e = np.eye(n+1, dtype=int)
for i in range(n-1):
    a, b = map(int, input().split())
    e[a][b] = 1

for i in reversed(range(1, n+1)):
    for j in range(1, i):
        if e[i-j][i] == 1:
            e[i-j][i+1:] += e[i][i+1:]
        else:
            continue


point = np.zeros(n, dtype=int)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x
print(e[1:, 1:])
ans = np.dot(point, e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, q = map(int, input().split())

e = np.eye(n+1, dtype=int)
for i in range(n-1):
    a, b = map(int, input().split())
    e[a][b] = 1

for i in reversed(range(1, n+1)):
    for j in range(1, i):
        if e[i-j][i] == 1:
            e[i-j][i+1:] += e[i][i+1:]
        else:
            continue


point = np.zeros(n, dtype=int)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x
print(e[1:, 1:])
ans = np.dot(point, e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, q = map(int, input().split())

e = np.eye(n+1, dtype=int)
for i in range(n-1):
    a, b = map(int, input().split())
    e[a][b] = 1
print(reversed(range(2, n+1)))
for i in reversed(range(2, n+1)):
    for j in range(1, i-1):
        if e[i-j][i] == 1:
            e[i-j][i+1:] += e[i][i+1:]
        else:
            continue


point = np.zeros(n, dtype=int)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x

ans = np.dot(point, e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, q = map(int, input().split())

e = np.eye(n+1, dtype=int)
for i in range(n-1):
    a, b = map(int, input().split())
    e[a][b] = 1

for i in reversed(range(2, n+1)):
    if e[i-1][i] == 1:
        e[i-1][i+1:] += e[i][i+1:]
    else:
        continue


point = np.zeros(n, dtype=int)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x

ans = np.dot(point, e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, q = map(int, input().split())

e = np.eye(n+1, dtype=int)
for i in range(n-1):
    a, b = map(int, input().split())
    e[a][b] = 1

for i in reversed(range(1, n+1)):
    if e[i-1][i] == 1:
        e[i-1][i+1:] += e[i][i+1:]
    else:
        continue


point = np.zeros(n, dtype=int)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x

ans = np.dot(point, e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, q = map(int, input().split())

e = np.eye(n+1)
for i in range(n-1):
    a, b = map(int, input().split())
    e[a][b] = 1

for i in reversed(range(1, n+1)):
    if e[i-1][i] == 1:
        e[i-1][i+1:] += e[i][i+1:]
    else:
        continue


point = np.zeros(n)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x

ans = np.dot(point, e[1:, 1:])
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, q = map(int, input().split())

e = np.eye(n+1)

for i in range(n-1):
    a, b = map(int, input().split())
    e[a][b] = 1

for i in reversed(range(1, n+1)):
    if e[i-1][i] == 1:
        e[i-1][i+1:] += e[i][i+1:]
        print(e[1:, 1:])
    else:
        continue


point = np.zeros(n)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x

ans = np.dot(point, e[1:, 1:])
print(*ans)