And made a mistake of ZZ ...
It is important to note that the destroyed planet is not a unicom block (probably only I do it =)
Offline down time back, it becomes a map to add the planet, that is, with and check set maintenance Unicom, in the TOT variable record the current answer, each plus a planet on the tot++, each merge a unicom block on tot--
Note that a planet that has never been destroyed should be added to the map before the clock is back.
#include <iostream> #include <cstdio> #include <vector>using namespace Std;const int N=1000005;int n,m , Q,f[n],b[n],ans[n];bool V[n];vector<int>a[n];int Read () {int r=0,f=1; Char P=getchar (); while (p> ' 9 ' | | p< ' 0 ') {if (p== '-') f=-1; P=getchar (); } while (p>= ' 0 ' &&p<= ' 9 ') {r=r*10+p-48; P=getchar (); } return r*f;} int Zhao (int x) {return F[x]==x?x:f[x]=zhao (f[x]);} int main () {N=read (), M=read (); for (int i=1;i<=m;i++) {int x=read () +1,y=read () +1; A[x].push_back (y), a[y].push_back (x); } for (int i=1;i<=n;i++) f[i]=i; int tot=0; Q=read (); for (int i=q;i>=1;i--) b[i]=read () +1,v[b[i]]=1; for (int i=1;i<=n;i++) if (!v[i]) {tot++; for (int j=0;j<a[i].size (); j + +) if (!v[a[i][j]]) {int Fu=zhao (i), Fv=zha O (A[i][j]); if (FU!=FV) {F[FU]=FV; tot--; }}} for (int i=1;i<=q;i++) {ans[i]=tot++; v[b[i]]=0; for (int j=0;j<a[b[i]].size (); j + +) if (!v[a[b[i]][j]) {int Fu=zhao (b[i]), Fv=zhao (a [B[i]] [j]); if (FU!=FV) {F[FU]=FV; tot--; }}} printf ("%d\n", tot); for (int i=q;i>=1;i--) printf ("%d\n", Ans[i]); return 0;}
Bzoj 1015: [JSOI2008] Star Wars Starwar "and find"