#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; for (int i = 0; i < Q; i++) { int p, x; cin >> p >> x; p--; seen.assign(N,false); dfs(p,seen,T); int cnt = count(ALL(seen), true); ans += (ll)cnt * x; cout << ans << endl; } return 0; }