Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N,Q=map(int,input().split())
out=[set() for i in range(N+1)];out[0]=None # 頂点は1-initial
for j in range(N-1):
    a,b=map(int,input().split())
    out[a].add(b)
    out[b].add(a)
# print(out) #DB

a=[0 for i in range(N+1)];a[0]=None

for k in range(Q):
    p,x=map(int,input().split())
    a[p]+=x

# print(a) #DB
r=[False for i in range(N+1)];r[0]=None
q=deque()
q.append(1);r[1]=True
while q:
    u=q.popleft()
    for v in out[u]:
        if not r[v]:
            a[v]+=a[u]
            q.append(v)
            r[v]=True
            # print(q) #DB

print(*a[1:])

Fixed submission:
from collections import deque

N,Q=map(int,input().split())
out=[set() for i in range(N+1)];out[0]=None # 頂点は1-initial
for j in range(N-1):
    a,b=map(int,input().split())
    out[a].add(b)
    out[b].add(a)
# print(out) #DB

a=[0 for i in range(N+1)];a[0]=None

for k in range(Q):
    p,x=map(int,input().split())
    a[p]+=x

# print(a) #DB

q=deque()
q.append(1)
while q:
    u=q.popleft()
    for v in out[u]:
        a[v]+=a[u]
        q.append(v)
        out[v].remove(u)
        # print(q) #DB
    out[u].clear()

print(*a[1:])

Buggy python submission (verdict: Runtime Error):
def add(r):
    if r.next==[]:
        pass
    else:
        for v in r.next:
            v.val+=r.val
            add(v)

class Vertex:
    def __init__(self):
        self.val=0
        self.next=[]

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

V=[Vertex() for i in range(N)]

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

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

add(V[0])

for v in V:
    print(v.val,end=' ')

Fixed submission:
from collections import deque

N,Q=map(int,input().split())
out=[set() for i in range(N+1)];out[0]=None # 頂点は1-initial
for j in range(N-1):
    a,b=map(int,input().split())
    out[a].add(b)
    out[b].add(a)
# print(out) #DB

a=[0 for i in range(N+1)];a[0]=None

for k in range(Q):
    p,x=map(int,input().split())
    a[p]+=x

# print(a) #DB

q=deque()
q.append(1)
while q:
    u=q.popleft()
    for v in out[u]:
        a[v]+=a[u]
        q.append(v)
        out[v].remove(u)
        # print(q) #DB
    out[u].clear()

print(*a[1:])

Buggy python submission (verdict: Runtime Error):
def root(V):
    for v in V:
        if v.isroot:
            return v
    return None

def add(r):
    if r.next==[]:
        pass
    else:
        for v in r.next:
            v.val+=r.val
            add(v)

class Vertex:
    def __init__(self):
        self.val=0
        self.next=[]
        self.isroot=True

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

V=[Vertex() for i in range(N)]

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

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

r=root(V)
add(r)

for v in V:
    print(v.val,end=' ')

Fixed submission:
from collections import deque

N,Q=map(int,input().split())
out=[set() for i in range(N+1)];out[0]=None # 頂点は1-initial
for j in range(N-1):
    a,b=map(int,input().split())
    out[a].add(b)
    out[b].add(a)
# print(out) #DB

a=[0 for i in range(N+1)];a[0]=None

for k in range(Q):
    p,x=map(int,input().split())
    a[p]+=x

# print(a) #DB

q=deque()
q.append(1)
while q:
    u=q.popleft()
    for v in out[u]:
        a[v]+=a[u]
        q.append(v)
        out[v].remove(u)
        # print(q) #DB
    out[u].clear()

print(*a[1:])

Buggy python submission (verdict: Runtime Error):
def root(V):
    for v in V:
        if v.isroot:
            return v
    return None

def add(r):
    if r.next==[]:
        pass
    else:
        for v in r.next:
            v.val+=r.val
            add(v)

class Vertex:
    def __init__(self):
        self.val=0
        self.next=[]
        self.isroot=True

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

V=[Vertex() for i in range(N)]

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

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

r=root(V)
add(r)

for v in V:
    print(v.val,end=' ')

Fixed submission:
from collections import deque

N,Q=map(int,input().split())
out=[set() for i in range(N+1)];out[0]=None # 頂点は1-initial
for j in range(N-1):
    a,b=map(int,input().split())
    out[a].add(b)
    out[b].add(a)
# print(out) #DB

a=[0 for i in range(N+1)];a[0]=None

for k in range(Q):
    p,x=map(int,input().split())
    a[p]+=x

# print(a) #DB

q=deque()
q.append(1)
while q:
    u=q.popleft()
    for v in out[u]:
        a[v]+=a[u]
        q.append(v)
        out[v].remove(u)
        # print(q) #DB
    out[u].clear()

print(*a[1:])

Buggy python submission (verdict: Runtime Error):
def root(V): # i(Root)
    for i in range(len(V)):
        if V[i][1]==[]:
            return i
    return -1

def add(V,r): # add recursively
    for l in V[r][2]:
        V[l][0]+=V[r][0]
        add(V,l)

N,Q=map(int,input().split())
V=[[0,[],[]] for i in range(N)] # value,prev[],next[]

for i in range(N-1):
    a,b=map(int,input().split())
    V[a-1][2].append(b-1) # append i(Next) to Prev.next
    V[b-1][1].append(a-1) # append i(Prev) to Next.prev

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

add(V,root(V))

for v in V:
    print(v[0],end=' ')

Fixed submission:
from collections import deque

N,Q=map(int,input().split())
out=[set() for i in range(N+1)];out[0]=None # 頂点は1-initial
for j in range(N-1):
    a,b=map(int,input().split())
    out[a].add(b)
    out[b].add(a)
# print(out) #DB

a=[0 for i in range(N+1)];a[0]=None

for k in range(Q):
    p,x=map(int,input().split())
    a[p]+=x

# print(a) #DB

q=deque()
q.append(1)
while q:
    u=q.popleft()
    for v in out[u]:
        a[v]+=a[u]
        q.append(v)
        out[v].remove(u)
        # print(q) #DB
    out[u].clear()

print(*a[1:])