from functools import cache from math import inf import sys sys.setrecursionlimit(5000000) def printe(*args, end="\n", **kwargs): print(*args, end=end, file=sys.stderr, **kwargs) def main(): N, Q = map(int, input().split()) tree = [set() for _ in range(N)] for _ in range(N - 1): a, b = map(lambda n: int(n) - 1, input().split()) tree[a].add(b) tree[b].add(a) tree_size = [inf for _ in range(N)] @cache def dfs_size(start_idx: int, parent: int = -1) -> int: cur_size = 1 for neighbor in tree[start_idx]: if neighbor == parent: continue cur_size += dfs_size(neighbor, start_idx) tree_size[start_idx] = cur_size return cur_size dfs_size(0) total_cost = 0 for _ in range(Q): p, x = map(int, input().split()) p -= 1 total_cost += tree_size[p] * x print(total_cost) if __name__ == "__main__": main()