Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = [0]
    looked[0] = 0
    while(queue):
        now = queue.pop(0)
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = deque([0])
    looked[0] = 0
    while(queue):
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = [0]
    looked[0] = 0
    while(queue):
        now = queue.pop(0)
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = deque([0])
    looked[0] = 0
    while(queue):
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1 for _ in range(n)]
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0 for _ in range(n)]
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = [0]
    looked[0] = 0
    while(queue):
        now = queue.pop(0)
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = deque([0])
    looked[0] = 0
    while(queue):
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
node = [[]for _ in range(n)]
looked = [1 for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    node[b-1].append(a-1)
    node[a-1].append(b-1)
counter = [0 for _ in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x
queue = [0]
looked[0] = 0
while(len(queue)):
    now = queue.pop(0)
    for i in node[now]:
        if looked[i]:
            queue.append(i)
            counter[i] += counter[now]
            looked[i] = 0
print(" ".join(map(str,counter)))

Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = deque([0])
    looked[0] = 0
    while(queue):
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
node = [[]for _ in range(n)]
looked = [1 for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    node[b-1].append(a-1)
    node[a-1].append(b-1)
counter = [0 for _ in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x
queue = [0]
looked[0] = 0
while(len(queue)):
    now = queue.pop(0)
    for i in node[now]:
        if looked[i]:
            queue.append(i)
            counter[i] += counter[now]
            looked[i] = 0
print(" ".join(list(map(str,counter))))

Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = deque([0])
    looked[0] = 0
    while(queue):
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
node = [[]for _ in range(n)]
looked = [0 for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    node[b-1].append(a-1)
    node[a-1].append(b-1)
counter = [0 for _ in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x
queue = [0]
looked[0] = 1
while(len(queue)):
    now = queue.pop(0)
    for i in node[now]:
        if looked[i] == 0:
            queue.append(i)
            counter[i] += counter[now]
            looked[i] = 1
print(" ".join(list(map(str,counter))))

Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = deque([0])
    looked[0] = 0
    while(queue):
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
node = [[]for _ in range(n)]
looked = [0 for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    node[b-1].append(a-1)
    node[a-1].append(b-1)
counter = [0 for _ in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x
queue = [0]
looked[0] = 1
while(len(queue)):
    now = queue.pop(0)
    for i in node[now]:
        if looked[i] == 0:
            queue.append(i)
            counter[i] += counter[now]
            looked[i] = 1
print(" ".join(list(map(str,counter))))

Fixed submission:
from collections import deque
def main():
    n,q = map(int,input().split())
    node = [[]for _ in range(n)]
    looked = [1]*n
    for i in range(n-1):
        a,b = map(int,input().split())
        node[b-1].append(a-1)
        node[a-1].append(b-1)
    counter = [0]*n
    for i in range(q):
        p,x = map(int,input().split())
        counter[p-1] += x
    queue = deque([0])
    looked[0] = 0
    while(queue):
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
main()