is obviously not to do, we take the reverse and check set, the deletion point to add, each time the greedy think added a unicom block, once the discrepancy on the minus one.
1#include <bits/stdc++.h>2 using namespacestd;3 Const intn=4e6+Ten;4 BOOLDel[n],v[n];5 intf[n],p[n],head[n],cnt,tot,ans[n],n,m,k;6 int Get(intx) {returnx==f[x]?x:f[x]=Get(F[x]);}7 structnode{8 intTo,nex;9 }e[n];Ten voidADDD (intXintY) {e[++cnt].to=y;e[cnt].nex=head[x];head[x]=CNT;} One voidAddintx) A { - intfx=Get(x); - for(intI=head[x];i;i=E[i].nex) the { - inty=e[i].to; - if(V[y]) - { + intfy=Get(y); - if(FY!=FX) f[fy]=fx,tot--; + } A } at } - intMain () - { -scanf"%d%d", &n,&m);intx, y; - for(intI=1; i<=n;++i) f[i]=i; - for(intI=1; i<=m;++i) in { -scanf"%d%d",&x,&y); to addd (x, y); addd (y,x); + } -scanf"%d",&k); the for(intI=1; i<=k;++i) * { $scanf"%d",&p[i]);Panax Notoginsengdel[p[i]]=1; - } the for(intI=0; i<n;++i) + { A if(!Del[i]) the { +tot++; - Add (i); $v[i]=1; $ } - } -ans[0]=tot; the for(inti=k;i;--i) - {Wuyitot++; the Add (P[i]); -v[p[i]]=1; Wuans[k-i+1]=tot; - } About for(inti=k;i>=0;-i) printf ("%d\n", Ans[i]); $ return 0; -}
Bzoj [JSOI2008] Star Wars Starwar