Bzoj 1015: [JSOI2008] Star Wars Starwar "and check Set"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.