1#include <cstdio>2#include <iostream>3 #defineM 20000004 intcnt,fa[m],n,m,ans[m],k,f[m],a[m],head[m],next[2*m],u[2*M];5 intZhaointA1)6 {7     if(a1==FA[A1])8       returnA1;9fa[a1]=Zhao (fa[a1]);Ten     returnFA[A1]; One } A voidJiaintA1,intA2) - { -cnt++; thenext[cnt]=HEAD[A1]; -u[cnt]=A2; -head[a1]=CNT; -      return;  + } - intMain () + { Ascanf"%d%d",&n,&m); at      for(intI=1; i<=m;i++) -       { -         inta1,a2; -scanf"%d%d",&a1,&A2); -a1++; -a2++; in Jia (A1,A2); - Jia (a2,a1); to       } +scanf"%d",&k); -      for(intI=1; i<=k;i++) the       { *         intA1; $scanf"%d",&A1);Panax Notoginsenga[i]=++A1; -f[a1]=1; the       } +      for(intI=1; i<=n;i++) Afa[i]=i; theans[k]=n-K; +      for(intI=1; i<=n;i++) -       if(!F[i]) $          for(intj=head[i];j;j=Next[j]) $           if(!F[u[j]]) -             { -               intB1=zhao (i), b2=Zhao (u[j]); the               if(b1!=B2) -                {Wuyifa[b1]=B2; theans[k]--; -                }  Wu             } -      for(inti=k;i;i--) About       { $f[a[i]]=0; -ans[i-1]=ans[i]+1; -          for(intj=head[a[i]];j;j=Next[j]) -           if(!F[u[j]]) A             { +               intB1=zhao (A[i]), b2=Zhao (u[j]); the               if(b1!=B2) -               { $fa[b1]=B2; theans[i-1]--; the               } the             } the       } -      for(intI=0; i<=k;i++) inprintf"%d\n", Ans[i]); the     return 0; the}
The problem is offline to deal with the first delete all the deleted, and then add, use and check set maintenance can, of course, the deletion of the topic is the point, do not forget Ah!!
Bzoj 1015: [JSOI2008] Star Wars Starwar