#include #include #include #include using namespace std; #define ll long long vector>d; vectorcnt; vectorB; void f(int i){ B.at(i)=1; for(ll j:d.at(i)){ if(B.at(j)==0){ f(j); cnt.at(i)+=cnt.at(j); } } return; } int main(){ ll N,Q,a,b,ans=0,p,x; cin>>N>>Q; d.resize(N); cnt.resize(N); B.resize(N); for(int i=0;i>a>>b; d.at(a-1).push_back(b-1); d.at(b-1).push_back(a-1); } cnt.at(N-1)=1; f(0); for(int i=0;i>p>>x; ans+=cnt.at(p-1)*x; printf("%lld\n",ans); } return 0; }