from sys import stdin n, q, *indata = map(int, stdin.read().split()) offset = 0 g = [[] for i in range(n+1)] for i in range(n-1): s, t = indata[offset + 2*i],indata[offset + 2*i+1] g[s].append(t) g[t].append(s) dp = [0 for i in range(n+1)] check = [0 for i in range(n+1)] que = [(1,0)] while que: now, inout = que.pop() if inout == 0: check[now] = 1 que.append((now,1)) for i in g[now]: if check[i] == 0: que.append((i,0)) else: check[now] = 2 dp[now] = 1 for i in g[now]: if check[i] == 2: dp[now] += dp[i] offset = (n-1) * 2 ans = 0 for i in range(q): p, x = indata[offset + 2*i],indata[offset + 2*i+1] ans += x * dp[p] print("{}".format(ans))