#include #include using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll mod=998244353; ll inf=1009999999999999990; void dfs(ll now,vector>&g,vector&dp,vector&memo){ memo[now]=1; dp[now]=1; for (ll i = 0; i < g[now].size(); i++) { if (memo[g[now][i]]==0) { dfs(g[now][i],g,dp,memo); dp[now]+=dp[g[now][i]]; } } } int main(){ ll n,q; cin >>n >> q; vector>g(n); for (ll i = 0; i < n-1; i++) { ll a,b; cin >> a >> b; a--,b--; g[a].push_back(b); g[b].push_back(a); } vectordp(n,0); vectormemo(n,0); dfs(0,g,dp,memo); ll ans=0; vectora; for (ll i = 0; i < q; i++) { ll p,x; cin >> p >> x; p--; ans+=x*dp[p]; a.push_back(ans); } for (ll i = 0; i < a.size(); i++) { cout << a[i] << endl; } }