Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

import sys
sys.setrecursionlimit(100000)

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
#ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
#px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

ans = [0] * (N+1)
child = [[] for _ in range(N+1)]


def add(node, num):
    for x in child[node]:
        add(x, num)

    ans[node] += num

for a, b in [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]:
    child[a].append(b)

#print(child)

for p, x in [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]:
    ii = p
    add(p, x)

print(*ans[1:], sep=" ")

Fixed submission:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

node_value = [0] * (N+1)
parent = [-1] * (N+1)

for a, b in ab:
    parent[b] = a

for p, x in px:
    node_value[p] += x

#print(parent)

ans = [0] * (N+1)

for i in range(1, N+1):
    ans[i] = node_value[i]
    if parent[i] != -1:
        ans[i] += ans[parent[i]]

print(*ans[1:], sep=" ")

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

import sys
sys.setrecursionlimit(100000)

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
#ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
#px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

ans = [0] * (N+1)
child = []
for _ in range(N+1):
    child.append([])

def add(node, num):
    for x in child[node]:
        add(x, num)

    ans[node] += num

for a, b in [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]:
    child[a].append(b)

#print(child)

for p, x in [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]:
    add(p, x)

print(*ans[1:], sep=" ")

Fixed submission:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

node_value = [0] * (N+1)
parent = [-1] * (N+1)

for a, b in ab:
    parent[b] = a

for p, x in px:
    node_value[p] += x

#print(parent)

ans = [0] * (N+1)

for i in range(1, N+1):
    ans[i] = node_value[i]
    if parent[i] != -1:
        ans[i] += ans[parent[i]]

print(*ans[1:], sep=" ")

Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

import sys
sys.setrecursionlimit(100000)

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
#ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
#px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

ans = [0] * (N+1)
child = []
for _ in range(N+1):
    child.append([])

def add(node, num):
    for x in child[node]:
        add(x, num)

    ans[node] += num

for a, b in [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]:
    child[a].append(b)

#print(child)

for p, x in [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]:
    add(p, x)

print(*ans[1:], sep=" ")

Fixed submission:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

node_value = [0] * (N+1)
parent = [-1] * (N+1)

for a, b in ab:
    parent[b] = a

for p, x in px:
    node_value[p] += x

#print(parent)

ans = [0] * (N+1)

for i in range(1, N+1):
    ans[i] = node_value[i]
    if parent[i] != -1:
        ans[i] += ans[parent[i]]

print(*ans[1:], sep=" ")

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

import sys
sys.setrecursionlimit(100000)

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

ans = [0] * (N+1)
child = []
for _ in range(N+1):
    child.append([])

def add(node, num):
    for x in child[node]:
        add(x, num)

    ans[node] += num

for a, b in ab:
    child[a].append(b)

#print(child)

for p, x in px:
    add(p, x)

print(*ans[1:], sep=" ")

Fixed submission:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N <= 2*10^5
# Q <= 2*10^5
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
px = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

node_value = [0] * (N+1)
parent = [-1] * (N+1)

for a, b in ab:
    parent[b] = a

for p, x in px:
    node_value[p] += x

#print(parent)

ans = [0] * (N+1)

for i in range(1, N+1):
    ans[i] = node_value[i]
    if parent[i] != -1:
        ans[i] += ans[parent[i]]

print(*ans[1:], sep=" ")