import itertools as iter import collections as coll import heapq as hq import bisect as bis from decimal import Decimal as dec from copy import deepcopy as dcopy import math import sys sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def getN(): return int(sys.stdin.readline().rstrip()) def getNs(): return map(int,sys.stdin.readline().rstrip().split()) def getList(): return list(map(int,sys.stdin.readline().rstrip().split())) def strinps(n): return [sys.stdin.readline().rstrip() for _ in range(n)] pi = 3.141592653589793 mod = 10**9+7 MOD = 998244353 INF = math.inf dx = [1,0,-1,0]; dy = [0,1,0,-1] """ Main Code """ n,q = getNs() route = [[] for _ in [0]*n] for _ in [0]*(n-1): a,b = getNs() a -= 1; b -= 1 route[a].append(b) route[b].append(a) visited = [False]*n cnt = [0]*n def dfs(v): res = 1 for nv in route[v]: if not(visited[nv]): visited[nv] = True res += dfs(nv) cnt[v] = res return res visited[0] = True dfs(0) ans = 0 query = [getList() for _ in [0]*q] for p,x in query: ans += x*cnt[p-1] print(ans)