Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8 
# Your code here!
import sys 
sys.setrecursionlimit(100000000)

N,Q=map(int,input().split()) 

l=[[i] for i in range(N)] 

#print(l) 
def dfs(num,point,visited): 
    visited[num]=1 
    point+=plus[num] 
    
    ans[num]=point 
    while l[num][-1]!=num: 
        temp=l[num].pop(-1) 
        if visited[temp]==0: 
            dfs(temp,point,visited) 
            
    return 0 

for _ in range(N-1): 
    a,b=map(int,input().split()) 
    l[a-1].append(b-1) 
    l[b-1].append(a-1) 
    
ans=[0]*N 
plus=[0]*N 

for _ in range(Q): 
    p,x=map(int,input().split()) 
    plus[p-1]+=x 

dfs(0,0,[0]*N) 

print(*ans)


Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8 
# Your code here!
import sys 
sys.setrecursionlimit(100000000)

N,Q=map(int,input().split()) 

l=[[i] for i in range(N)] 

#print(l) 
def dfs(num,point,visited): 
    visited[num]=1 
    point+=plus[num] 
    
    ans[num]=point 
    while l[num][-1]!=num: 
        temp=l[num].pop(-1) 
        if visited[temp]==0: 
            dfs(temp,point,visited) 
            
    return 0 

for _ in range(N-1): 
    a,b=map(int,input().split()) 
    l[a-1].append(b-1) 
    l[b-1].append(a-1) 
    
ans=[0]*N 
plus=[0]*N 

for _ in range(Q): 
    p,x=map(int,input().split()) 
    plus[p-1]+=x 

dfs(0,0,[0]*N) 

print(*ans)


Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])

Buggy python submission (verdict: Runtime Error):
# coding: utf-8 
# Your code here!
import sys 
sys.setrecursionlimit(10000000000)

N,Q=map(int,input().split()) 

l=[[i] for i in range(N)] 

#print(l) 
def dfs(num,point,visited): 
    visited[num]=1 
    point+=plus[num] 
    
    ans[num]=point 
    while l[num][-1]!=num: 
        temp=l[num].pop(-1) 
        if visited[temp]==0: 
            dfs(temp,point,visited) 
            
    return 0 

for _ in range(N-1): 
    a,b=map(int,input().split()) 
    l[a-1].append(b-1) 
    l[b-1].append(a-1) 
    
ans=[0]*N 
plus=[0]*N 

for _ in range(Q): 
    p,x=map(int,input().split()) 
    plus[p-1]+=x 

dfs(0,0,[0]*N) 

print(*ans)


Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])

Buggy python submission (verdict: Runtime Error):
# coding: utf-8 
# Your code here!
import sys 
sys.setrecursionlimit(40000)

N,Q=map(int,input().split()) 

l=[[i] for i in range(N)] 

#print(l) 
def dfs(num,point,visited): 
    visited[num]=1 
    point+=plus[num] 
    
    ans[num]=point 
    while l[num][-1]!=num: 
        temp=l[num].pop(-1) 
        if visited[temp]==0: 
            dfs(temp,point,visited) 
            
    return 0 

for _ in range(N-1): 
    a,b=map(int,input().split()) 
    l[a-1].append(b-1) 
    l[b-1].append(a-1) 
    
ans=[0]*N 
plus=[0]*N 

for _ in range(Q): 
    p,x=map(int,input().split()) 
    plus[p-1]+=x 

dfs(0,0,[0]*N) 

print(*ans)


Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N,Q=map(int,input().split())

l=[[i] for i in range(N)]
#print(l)

def dfs(num,point,visited):
    visited[num]=1
    point+=plus[num]
    ans[num]=point
    
    while l[num][-1]!=num:
        temp=l[num].pop(-1)
        if visited[temp]==0:
            dfs(temp,point,visited)
        
    return 0

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

ans=[0]*N
plus=[0]*N
for _ in range(Q):
    p,x=map(int,input().split())
    
    plus[p-1]+=x
    
dfs(0,0,[0]*N)
    
print(*ans)

Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

N,Q=map(int,input().split())

root=[i for i in range(N)]

ketsu=[[]*(N) for i in range(N)]
point=[0]*N
ans=[0]*N

def dfs(num,value):
    ans[num]+=value
    for item in ketsu[num]:
        dfs(item,value+point[item])
            

for _ in range(N-1):
    a,b=map(int,input().split())
    ketsu[a-1].append(b-1)
    #ketsu[b-1].append(a-1)
    root.remove(b-1)
    
for _ in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
#print(point)

for item in root:
    dfs(item,point[item])
    
print(*ans)

Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
#sys.setrecursionlimit(1000000)

N,Q=map(int,input().split())
l=[[]*N for i in range(N)]
temp=[0]*N
ans=[0]*N

def dfs(i,value):
    ans[i]+=value
    for item in l[i]:
        dfs(item,value+temp[item])

for i in range(N-1):
    a,b=map(int,input().split())
    l[a-1].append(b-1)
    #l[b-1].append(a-1)


for i in range(Q):
    p,x=map(int,input().split())
    temp[p-1]+=x

dfs(0,temp[0])

print(*ans)


Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

N,Q=map(int,input().split())
l=[[]*N for i in range(N)]
temp=[0]*N
ans=[0]*N

def dfs(i,value):
    ans[i]+=value
    for item in l[i]:
        dfs(item,value+temp[item])

for i in range(N-1):
    a,b=map(int,input().split())
    l[a-1].append(b-1)
    #l[b-1].append(a-1)


for i in range(Q):
    p,x=map(int,input().split())
    temp[p-1]+=x

dfs(0,temp[0])

print(*ans)


Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])

Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
l=[[]*N for i in range(N)]
ans=[0]*N


def add(index,value):
    ans[index]+=value
    for i in range(N):
        if l[index][i]==1:
            add(i,value)
    return    

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

for i in range(N-1)[::-1]:
    for item in l[i]:
        l[i]=l[i]+l[item]

print(l)

for i in range(Q):
    p,x=map(int,input().split())
    add(p-1,x)

print(*ans)


Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])

Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
side=[[0 for i in range(2)]for j in range(N-1)]
yobun=[[0 for i in range(2)]for j in range(Q)]

l=[0]*N
ll=[0 for i in range(N)] for j in range(N)

for i in range(N-1):
    side[i][0],side[i][1]=map(int,input().split())
    
def kyusyu(p,x):
    l[p-1]+=x
    for i in range(N-1):
        if p==side[i][0]:
            kyusyu(side[i][1],x)
    
for i in range(Q):
    yobun[i][0],yobun[i][1]=map(int,input().split())
    kyusyu(yobun[i][0],yobun[i][1])



            
#for i in range(Q):
#    kyusyu(yobun[i][0],yobun[i][1])
    
    
print(l)
    

Fixed submission:
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[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())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])