"And check Set" bzoj1015 [JSOI2008] Star Wars Starwar

Source: Internet
Author: User

To deal with the deleted point backwards, it becomes a little bit, so and check set.

#include <cstdio>using namespace std; #define N 400001int Fa[n],kill[n],rank[n],n,m,q;bool hav[n];int Next[n], First[n],v[n],en,x,y,anss[n],cnt;void Addedge (int u,int v) {v[++en]=v;next[en]=first[u];first[u]=en;} int find (int x) {if (x==fa[x]) return X;fa[x]=find (Fa[x]); return fa[x];}  void Union (int u,int V) {--cnt;if (Rank[u]<rank[v]) fa[u]=v;else {fa[v]=u;  if (Rank[u]==rank[v]) ++rank[u]; }}int Main () {scanf ("%d%d", &n,&m), cnt=n;for (int i=0;i<n;++i) fa[i]=i;for (int i=1;i<=m;++i) {scanf ("%d%  D ", &x,&y); Addedge (x, y);  Addedge (Y,X);  }SCANF ("%d", &q), for (int i=1;i<=q;++i) {scanf ("%d", &kill[i]);  Hav[kill[i]]=1; }for (int i=0;i<n;++i) if (!hav[i]) for (int j=first[i];j;j=next[j]) if (!hav[v[j]]) {int F1=find (i), f2=f        IND (V[j]);      if (F1!=F2) Union (F1,F2);  }for (int i=q;i>=1;--i) {anss[i]=cnt-i;        for (int j=first[kill[i]];j;j=next[j]) if (!hav[v[j]) {int f1=find (kill[i]), F2=find (V[j]); if (F1!=F2) Union (F1,F2);  } hav[kill[i]]=0; }anss[0]=cnt;for (int i=0;i<=q;++i) printf ("%d\n", Anss[i]); return 0;}

and check set bzoj1015 [JSOI2008] Star Wars Starwar

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.