Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
def dfs(i,we):
    global adj,co,res,vis
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if vis[j]==0:
            vis[j]=1
            adj[j].remove(i)
            dfs(j,we)
            
    
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
vis=[0]*n
vis[0]=1
dfs(0,0)
for i in range(n):
    print(res[i],end=" ")
print()



Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def dfs(i,we,par):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if j!=par:
            dfs(j,we,i)
            
input = sys.stdin.readline
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
dfs(0,0,None)
for i in range(n):
    print(res[i],end=" ")
print()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
def dfs(i,we):
    global adj,co,res,vis
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if vis[j]==0:
            vis[j]=1
            adj[j].remove(i)
            dfs(j,we)
            
    
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
vis=[0]*n
vis[0]=1
dfs(0,0)
for i in range(n):
    print(res[i],end=" ")
print()



Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def dfs(i,we,par):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if j!=par:
            dfs(j,we,i)
            
input = sys.stdin.readline
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
dfs(0,0,None)
for i in range(n):
    print(res[i],end=" ")
print()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
def dfs(i,we):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if vis[j]==0:
            vis[j]=1
            dfs(j,we)
            
    
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
vis=[0]*n
vis[0]=1
dfs(0,0)
for i in range(n):
    print(res[i],end=" ")
print()



Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def dfs(i,we,par):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if j!=par:
            dfs(j,we,i)
            
input = sys.stdin.readline
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
dfs(0,0,None)
for i in range(n):
    print(res[i],end=" ")
print()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
def dfs(i,we):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if vis[j]==0:
            vis[j]=1
            dfs(j,we)
            
    
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
vis=[0]*n
vis[0]=1
dfs(0,0)
for i in range(n):
    print(res[i],end=" ")
print()



Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def dfs(i,we,par):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if j!=par:
            dfs(j,we,i)
            
input = sys.stdin.readline
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
dfs(0,0,None)
for i in range(n):
    print(res[i],end=" ")
print()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
def dfs(i,we):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if vis[j]==0:
            vis[j]=1
            dfs(j,we)
            
    
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
vis=[0]*n
vis[0]=1
dfs(0,0)
for i in range(n):
    print(res[i],end=" ")
print()



Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def dfs(i,we,par):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if j!=par:
            dfs(j,we,i)
            
input = sys.stdin.readline
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
dfs(0,0,None)
for i in range(n):
    print(res[i],end=" ")
print()