提交时间:2022-04-11 11:09:52
运行 ID: 48239
#include <bits/stdc++.h> using namespace std; inline long long read() { int x=0,f=1; char t=getchar(); while(t<'0'||t>'9'){if(t=='-')f=0;t=getchar();} while(t>='0'&&t<='9')x=(x<<1)+(x<<3)+(t^48),t=getchar(); return f?x:-x; } const int N=2e5+100; int n,m,t,u,v,cntt[N],ans=1,ct[N],cct[N],otherans[N]; bool bj[N]; vector<int> a[N]; deque<int> q; void dfs(int k) { bj[k]=true; for(int it=0;it<a[k].size();it++) ct[a[k][it]]++,dfs(a[k][it]); } void Top1() { int tt=n; while(q.size()) { if(a[q.back()].empty()) ans=max(cntt[q.back()],ans); else for(int it=0;it<a[q.back()].size();it++) { cntt[a[q.back()][it]]+=cntt[q.back()],ct[a[q.back()][it]]--; if(ct[a[q.back()][it]]==0)q.push_front(a[q.back()][it]);} q.pop_back(); } } void Top() { int tt=n; while(q.size()) { if(a[q.back()].empty()) ans=max(ans,otherans[q.back()]*cntt[q.back()]); else for(int it=0;it<a[q.back()].size();it++) { cntt[a[q.back()][it]]+=cntt[q.back()],ct[a[q.back()][it]]--; if(ct[a[q.back()][it]]==0)q.push_front(a[q.back()][it]);} q.pop_back(); } } int main() { freopen("game.in","r",stdin); freopen("game.out","w",stdout); n=read(),m=read(),t=read(); for(int i=1;i<=m;i++) u=read(),v=read(),a[u].push_back(v),ct[v]++,cct[v]++; cntt[1]=1; q.push_front(1); Top1(); cout<<ans<<endl; for(int i=1;i<=n;i++) otherans[i]=ans/cntt[i]; while(t--) { cin>>u>>v; cntt[v]+=cntt[u]; memset(bj,false,sizeof(bj)); dfs(v); q.push_front(v); Top(); for(int i=1;i<=n;i++) // if(bj[i]) otherans[i]=ans/cntt[i]; cout<<ans<<endl; } return 0; }