#include using namespace std; #include using namespace atcoder; using ll=long long; using Graph=vector>; #define MAX 2000000 #define MOD 1000000007 #define INF 1000000000 void dfs(Graph &G,int v,int p,vector &cnt){ cnt[v]=1; for(auto nv:G[v]){ if(nv==p){ continue; } dfs(G,nv,v,cnt); cnt[v]+=cnt[nv]; } } int main(){ int N,Q; cin>>N>>Q; Graph G(N); for(int i=0;i>a>>b; a--;b--; G[a].push_back(b); G[b].push_back(a); } vector cnt(N); dfs(G,0,-1,cnt); ll ans=0; for(int i=0;i>p>>x; p--; ans+=(ll)cnt[p]*(ll)x; cout<