#include using namespace std; struct Edge { int u; int v; int cost; Edge(int a, int b, int c) : u(a), v(b), cost(c) { } }; using Graph = vector>; vector depth; vector subtree_size; void dfs(const Graph& G, int v, int p, int d) { depth[v] = d; for (auto nv : G[v]) { if (nv.v == p) continue; dfs(G, nv.v, v, d + 1); } subtree_size[v] = 1; for (auto c : G[v]) { if (c.v == p) continue; subtree_size[v] += subtree_size[c.v]; } } int main() { long long N, Q; cin >> N >> Q; Graph G(N); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; G[a - 1].emplace_back(a - 1, b - 1, 1); G[b - 1].emplace_back(b - 1, a - 1, 1); } depth.assign(N, 0); subtree_size.assign(N, 0); dfs(G, 0, -1, 0); long long ans = 0; for (int i = 0; i < Q; i++) { long long p, x; cin >> p >> x; ans += subtree_size[p - 1] * x; } }