Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys


def main():
    n, q = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

    tree = {}
    data = [0 for x in range(n)]

    for _ in range(n - 1):
        a, b = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
        if a not in tree:
            tree[a] = []
        tree[a].append(b)

    for _ in range(q):
        p, x = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
        data[p - 1] += x

    def add(p, x):
        data[p - 1] += x
        if p not in tree:
            return
        for p2 in tree[p]:
            add(p2, data[p - 1])

    add(1, 0)

    print(" ".join([str(x) for x in data]))


if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

import sys


sys.setrecursionlimit(10**6)


def main():
    n, q = map(int, sys.stdin.readline().split())

    tree = [[] for x in range(n + 1)]
    data = [0 for x in range(n + 1)]

    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(q):
        p, x = map(int, sys.stdin.readline().split())
        data[p] += x

    def dfs(p, p2, x):
        data[p] += x
        for p3 in tree[p]:
            if p3 == p2:
                continue
            dfs(p3, p, data[p])

    dfs(1, 0, 0)

    print(" ".join([str(x) for x in data[1:]]))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict


n, q = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

tree = defaultdict(list)
data = defaultdict(int)


def add(p, x):
    data[p] += x
    for p2 in tree[p]:
        add(p2, x)


for _ in range(n - 1):
    a, b = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    tree[a].append(b)

for _ in range(q):
    p, x = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    add(p, x)

print(" ".join([str(data[i + 1]) for i in range(n)]))


Fixed submission:
# -*- coding: utf-8 -*-

import sys


sys.setrecursionlimit(10**6)


def main():
    n, q = map(int, sys.stdin.readline().split())

    tree = [[] for x in range(n + 1)]
    data = [0 for x in range(n + 1)]

    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(q):
        p, x = map(int, sys.stdin.readline().split())
        data[p] += x

    def dfs(p, p2, x):
        data[p] += x
        for p3 in tree[p]:
            if p3 == p2:
                continue
            dfs(p3, p, data[p])

    dfs(1, 0, 0)

    print(" ".join([str(x) for x in data[1:]]))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict


n, q = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

tree = defaultdict(set)
data = defaultdict(int)


def add(p, x):
    data[p] += x
    for p2 in tree[p]:
        add(p2, x)


for _ in range(n - 1):
    a, b = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    tree[a].add(b)

for _ in range(q):
    p, x = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    add(p, x)

print(" ".join([str(data[i + 1]) for i in range(n)]))


Fixed submission:
# -*- coding: utf-8 -*-

import sys


sys.setrecursionlimit(10**6)


def main():
    n, q = map(int, sys.stdin.readline().split())

    tree = [[] for x in range(n + 1)]
    data = [0 for x in range(n + 1)]

    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(q):
        p, x = map(int, sys.stdin.readline().split())
        data[p] += x

    def dfs(p, p2, x):
        data[p] += x
        for p3 in tree[p]:
            if p3 == p2:
                continue
            dfs(p3, p, data[p])

    dfs(1, 0, 0)

    print(" ".join([str(x) for x in data[1:]]))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict


n, q = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

tree = defaultdict(set)
data = {}


def add(p, x):
    global data
    data[p] += x
    for p2 in tree[p]:
        add(p2, x)


for _ in range(n - 1):
    a, b = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    tree[a].add(b)

for k, v in tree.items():
    data[k] = 0
    for v2 in v:
        data[v2] = 0

for _ in range(q):
    p, x = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    add(p, x)

print(" ".join([str(v) for k, v in sorted(data.items(), key=lambda x: x[0])]))


Fixed submission:
# -*- coding: utf-8 -*-

import sys


sys.setrecursionlimit(10**6)


def main():
    n, q = map(int, sys.stdin.readline().split())

    tree = [[] for x in range(n + 1)]
    data = [0 for x in range(n + 1)]

    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(q):
        p, x = map(int, sys.stdin.readline().split())
        data[p] += x

    def dfs(p, p2, x):
        data[p] += x
        for p3 in tree[p]:
            if p3 == p2:
                continue
            dfs(p3, p, data[p])

    dfs(1, 0, 0)

    print(" ".join([str(x) for x in data[1:]]))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict


n, q = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

tree = defaultdict(set)
data = {}


def add(p, x):
    global data
    data[p] += x
    for p2 in tree[p]:
        add(p2, x)


for _ in range(n - 1):
    a, b = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    tree[a].add(b)

for k in tree.keys():
    data[k] = 0

for _ in range(q):
    p, x = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    add(p, x)

print(" ".join([str(v) for k, v in sorted(data.items(), key=lambda x: x[0])]))


Fixed submission:
# -*- coding: utf-8 -*-

import sys


sys.setrecursionlimit(10**6)


def main():
    n, q = map(int, sys.stdin.readline().split())

    tree = [[] for x in range(n + 1)]
    data = [0 for x in range(n + 1)]

    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(q):
        p, x = map(int, sys.stdin.readline().split())
        data[p] += x

    def dfs(p, p2, x):
        data[p] += x
        for p3 in tree[p]:
            if p3 == p2:
                continue
            dfs(p3, p, data[p])

    dfs(1, 0, 0)

    print(" ".join([str(x) for x in data[1:]]))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict


n, q = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

tree = defaultdict(set)
data = defaultdict(int)


def add(p, x):
    global data
    data[p] += x
    for p2 in tree[p]:
        add(p2, x)


for _ in range(n - 1):
    a, b = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    tree[a].add(b)

for _ in range(q):
    p, x = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
    add(p, x)

print(" ".join([str(v) for k, v in sorted(data.items(), key=lambda x: x[0])]))


Fixed submission:
# -*- coding: utf-8 -*-

import sys


sys.setrecursionlimit(10**6)


def main():
    n, q = map(int, sys.stdin.readline().split())

    tree = [[] for x in range(n + 1)]
    data = [0 for x in range(n + 1)]

    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(q):
        p, x = map(int, sys.stdin.readline().split())
        data[p] += x

    def dfs(p, p2, x):
        data[p] += x
        for p3 in tree[p]:
            if p3 == p2:
                continue
            dfs(p3, p, data[p])

    dfs(1, 0, 0)

    print(" ".join([str(x) for x in data[1:]]))


if __name__ == "__main__":
    main()