#define _GLIBCXX_DEBUG #include using namespace std; using Graph = vector>; int main() { int N,Q; cin >> N >> Q; Graph G(N+1); for (int i=0; i> a >> b; G[a].push_back(b); G[b].push_back(a); } vectordepth(N+1,0); stackS; S.push(1); vectorseen(N+1,false); seen[1]=true; while(S.size()!=0) { int x=S.top(); S.pop(); for (auto next: G[x]) { if (seen[next]) { continue; } else { depth[next]=depth[x]+1; seen[next]=true; S.push(next); } } } vectorP(N+1,1); P[1]=N; for (int i=2; i<=N; i++) { stackA; A.push(i); vectorsee(N+1,false); see[i]=true; while (A.size()!=0) { int x=A.top(); A.pop(); for (auto next: G[x]) { if (!(see[next]) && depth[next]>depth[x]) { see[next]=true; A.push(next); P[i]++; } } } } long int ans=0; for (int i=0; i> p >> x; ans+=P[p]*x; cout << ans << endl; } }