Problem p02936 (python)

Fixed submission:
from collections import OrderedDict
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
#初期データ、構造
N,Q = (int(x) for x in input().split())
connection ={i:set() for i in range(1,N+1)}
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connection[a].add(b)
    connection[b].add(a)
#point =OrderedDict({i:0 for i in range(1,N+1)})
point ={i:0 for i in range(1,N+1)}
for i in range(Q):
    p,x = (int(x) for x in input().split())
    point[p] +=x

def DFS(now,prev = -1):
    for next in connection[now]:
        if next == prev:
            continue
        point[next] +=point[now] 
        DFS(next,now)

DFS(1)
print(*point.values())

Buggy submission (verdict: Runtime Error):
from collections import OrderedDict
#初期データ、構造
N,Q = (int(x) for x in input().split())
connection ={i:set() for i in range(1,N+1)}
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connection[a].add(b)
    connection[b].add(a)
#point =OrderedDict({i:0 for i in range(1,N+1)})
point ={i:0 for i in range(1,N+1)}
for i in range(Q):
    p,x = (int(x) for x in input().split())
    point[p]=x

def DFS(now,prev = -1):
    for next in connection[now]:
        if next == prev:
            continue
        point[next] +=point[now] 
        DFS(next,now)

DFS(1)
print(*point.values())

Buggy submission (verdict: Runtime Error):
from collections import OrderedDict
#初期データ、構造
N,Q = (int(x) for x in input().split())
connection ={i:set() for i in range(1,N+1)}
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connection[a].add(b)
    connection[b].add(a)
point =OrderedDict({i:0 for i in range(1,N+1)})
#point ={i:0 for i in range(1,N+1)}
for i in range(Q):
    p,x = (int(x) for x in input().split())
    point[p]=x

def DFS(now,prev = -1):
    for next in connection[now]:
        if next == prev:
            continue
        point[next] +=point[now] 
        DFS(next,now)

DFS(1)
print(*point.values())

Buggy submission (verdict: Runtime Error):
from collections import OrderedDict
#初期データ、構造
N,Q = (int(x) for x in input().split())
connection ={i:set() for i in range(1,N+1)}
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connection[a].add(b)
    connection[b].add(a)
point =OrderedDict({i:0 for i in range(1,N+1)})
#point ={i:0 for i in range(1,N+1)}
for i in range(Q):
    p,x = (int(x) for x in input().split())
    point[p]=x

def DFS(now,prev = -1):
    for next in connection[now]:
        if next == prev:
            continue
        point[next] +=point[now] 
        DFS(next,now)

DFS(1)
print(*point.values())

Buggy submission (verdict: Runtime Error):
# 初期入力
import numpy as np 
N,Q = (int(x) for x in input().split())
aa=0  
bb=0
a=[0] 
b=[0]
a_set =set()
ki_kouzou =np.zeros((N+1,1),dtype=np.int32)
ki_kouzou_dic ={i:set() for i in range(1,N+1)}

#木の構造を入力
for i in range(1,N): #直接つながっているところ。
    aa,bb = (int(x) for x in input().split())
    if bb in a_set: #親子判定 頂点3⇒頂点2もありうる
        #np.append(ki_kouzou[bb,:],aa,axis=1)
        a_set.add(aa)
        ki_kouzou_dic[bb].add(aa)
    else:
        #np.append(ki_kouzou[aa,:],bb,axis=1)
        #ki_kouzou[aa].append(bb)
        ki_kouzou_dic[aa].add(bb)
        a_set.add(bb)
    a.append(aa)     
    b.append(bb)


#間接的に繋がっているところ
kansetu ={i:set() for i in range(1,N+1)}
for ki_key in range(1,N+1) :
    for v_v in ki_kouzou_dic[ki_key]:
        if v_v in ki_kouzou_dic.keys():
            kansetu[ki_key] = kansetu[ki_key] | ki_kouzou_dic[v_v] 

for i in range(1,N+1):
    ki_kouzou_dic[i] =ki_kouzou_dic[i] | kansetu[i] #直接 ＋ 間接
    ki_kouzou_dic[i].add(i) #各頂点自身はは必ずポイント加算あり


# ポイント入力-計算
point={i:0 for i in range(1,N+1)}
pp=0 ; xx=0
for _ in range(Q):
    pp,xx = (int(x) for x in input().split())
    for i in ki_kouzou_dic[pp]:
        point[i] += xx 

print(*point.values())

Buggy submission (verdict: Runtime Error):
# 初期入力
import numpy as np 
N,Q = (int(x) for x in input().split())
aa=0  
bb=0
a=[0] 
b=[0]
ki_kouzou =np.zeros((N+1,N+1),dtype=int)

for i in range(1,N): #木の構造を入力
    aa,bb = (int(x) for x in input().split())
    ki_kouzou[aa,bb] =1
    a.append(aa) 
    b.append(bb)

#葉から根に向かい構造足していく
for i in range(N-1,0,-1):
    ki_kouzou[a[i],:] +=ki_kouzou[b[i],:]

for i in range(1,N+1): #各頂点は必ずフラグ立つ
    ki_kouzou[i,i] =1

# ポイント入力
p=[] ; x=[]
pp=0 ; xx=0
for i in range(Q):
    pp,xx = (int(x) for x in input().split())
    p.append(pp)
    x.append(xx)

#ポイント計算
point =np.zeros((N+1),dtype=int)
for i in range(Q):
    point +=ki_kouzou[p[i]] *x[i]

print(*point[1:])