#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; vectorp(Q); vectorx(Q); for (int i=0; i> p[i] >> x[i]; } for (int i=0; iA; A.push(y); vectorsee(N+1,false); see[y]=true; int count=1; 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); count++; } } } P[y]=count; } long int ans=0; for (int i=0; i