//#include #include #include using namespace std; //using namespace atcoder; using ll = long long; #define all(A) A.begin(),A.end() using vll = vector; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) using Graph = vector>; Graph G; vll E; vector seen; ll k = 0; void dfs(int v) { seen[v] = true; // v を訪問済にする // v から行ける各頂点 next_v について E[v] = k; for (auto next_v : G[v]) { if (seen[next_v]) continue; // next_v が探索済だったらスルー k++; dfs(next_v); // 再帰的に探索 } E[v] = k - E[v]; } int main() { ll N, Q; cin >> N >> Q; G.assign(N, {}); seen.assign(N, false); vll e(N, 0); E.assign(N, 0); rep(i, N - 1) { ll A, B; cin >> A >> B; A--; B--; G[A].push_back(B); G[B].push_back(A); } dfs(0); ll S = 0; rep(i, N) { cout << E[i] << endl; } rep(i, Q) { ll P, Q; cin >> P >> Q; S += (E[P - 1]+1) * Q; cout << S << endl; } }