#include #include using namespace std; using namespace atcoder; #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() using ll = long long; template inline bool chmin(T& a, T b) { if ( a > b ) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if ( a < b ) { a = b; return true; } return false; } const int INF = 1 << 30; void dfs(int v, vector &seen,vector>& G) { if(seen[v]) return; seen[v] = true; for(int& nv: G[v]) dfs(nv, seen, G); } int main() { int N, Q; cin >> N >> Q; vector> T(N); for (int i = 0; i < N-1; i++) { int a, b; cin >> a >> b; a--; b--; T[a].emplace_back(b); } ll ans = 0; vector seen; vector s(N); for (int i = 0; i < Q; i++) { ll p, x, cnt; cin >> p >> x; p--; if(s[p] == 0) { seen.assign(N,false); dfs(p,seen,T); s[p] = count(ALL(seen), true); } ans += s[p] * x; cout << ans << endl; } return 0; }