#include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; vector g[100000]; ll ch[100000]; bool used[100000]; void dfs(int v){ used[v] = true; ch[v] = 1; for(int to: g[v]){ if(!used[to]) { dfs(to); ch[v] += ch[to]; } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, q; cin >> n >> q; for(int i = 0; i < n-1; i++){ int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } ll ans = 0; dfs(0); while(q--){ int p, x; cin >> p >> x; p--; ans += ch[p]*x; cout << ans << endl; } }