#include using namespace std; int main(){ int N,Q; cin>>N>>Q; vector>G(N); for(int i=0,a,b;i>a>>b; --a,--b; G[a].push_back(b); G[b].push_back(a); } vector>dist(N); for(int i=0;ibfs; bfs.push(0); while(bfs.size()){ int t=bfs.front(); bfs.pop(); for(int i:G[t]){ if(dist[i][0]>dist[t][0]+1){ dist[i][0]=dist[t][0]+1; bfs.push(i); } } } auto dist2=dist; sort(dist.begin(),dist.end(),greater>()); vectorsz(N,1); for(int i=0;i>p>>x; ans+=x*sz[p-1]; cout<