|
- #include<cstdio>
- #define FOR(i,a,b) for(register int i=a;i<=b;i++)
- #define ROF(i,a,b) for(register int i=a;i>=b;i--)
- using namespace std;
- const int M=400005;
- int n,m,k,f[M],head[M],bro[M],cnt,ans[M];
- struct Edge
- {
- int next,to,from;
- }e[M];
- bool Bro[M];
- inline void add(int x,int y)
- {
- e[++cnt].next=head[x];
- e[cnt].to=y;
- e[cnt].from=x;
- head[x]=cnt;
- }
- int getf(int q)
- {
- if(f[q]==q)return q;
- f[q]=getf(f[q]);
- return f[q];
- }
- void Merge(int x,int y)
- {
- int t1=getf(f[x]),t2=getf(f[y]);
- if(t1!=t2)f[t1]=t2;
- return;
- }
- int main()
- {
- scanf("%d%d",&n,&m);
- FOR(i,0,n){f[i]=i;head[i]=-1;}
- FOR(i,1,m)
- {
- int a,b;scanf("%d%d",&a,&b);
- add(a,b);add(b,a);
- }
- scanf("%d",&k);
- FOR(i,1,k)
- {
- scanf("%d",&bro[i]);
- Bro[bro[i]]=1;
- }
- int tot=n-k;
- FOR(i,1,m<<1)
- if(!Bro[e[i].from])if(!Bro[e[i].to])if(getf(e[i].from)!=getf(e[i].to)){tot--;Merge(e[i].from,e[i].to);}
- ans[k+1]=tot;
- ROF(i,k,1)
- {
- tot++;
- Bro[bro[i]]=0;
- for(int j=head[bro[i]];j!=-1;j=e[j].next)
- if(!Bro[e[j].to] && getf(e[j].to)!=getf(bro[i])){tot--;Merge(e[j].to,bro[i]);}
- ans[i]=tot;
- }
- FOR(i,1,k+1)printf("%d\n",ans[i]);
- return 0;
- }
复制代码 |
|