Bzoj 1015: [JSOI2008] Star Wars Starwar and check set

Source: Internet
Author: User

1015: [JSOI2008] Star Wars Starwar

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

http://www.lydsy.com/JudgeOnline/problem.php?id=1015

Description long ago, in a distant galaxy, a dark empire was leaning against its super-weapons ruler throughout the galaxy. One day, with an occasional chance, a rebel army destroyed the empire's super weapons and attacked almost all the planets in the galaxy. These planets are connected to each other directly or indirectly through special etheric tunnels. But it was not long, and soon the Empire re-created his super weapon. With the power of this super weapon, the Empire began to plan to destroy the rebel-occupied planet. As the planet continues to be destroyed, communication channels between the two planets are beginning to be unreliable. Now, the rebel leader gives you a mission: to give the connection of the etheric tunnels between the original two planets and the order of the planets in the Empire's attack, to find out the number of connected fast planets that the rebels occupy after each strike as quickly as possible. (If two planets can be connected directly or indirectly through existing etheric channels, the two planets are in the same connected block).

Input

The first line of the input file contains two integers, n (1 <= n <= 2M) and M (1 <= m <= 200,000), respectively, representing the number of planets and the number of etheric tunnels. Planets are numbered with 0~n-1 integers. The next M-line, each line consists of two integers X, Y, where (0<=x<>y

Output

The first line of the output file is the number of connected blocks at the beginning of the planet. The next n rows, one integer per line, indicate the number of connected blocks of the existing planet after the strike.

Sample Input

8 13
0 1
1 6
6 5
5 0
0 6
1 2
2 3
3 4
4 5
7 1
9 |
7 6
3 6
5
1
6
3
5
7

Sample Output

1
1
1
2
3
3

HINT

Test instructions

Exercises

Just look backwards and check the set.

Directly engage

Code:

//Qscqesze#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<map>#include<stack>typedefLong Longll;using namespacestd;#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 1000000#defineMoD 10007#defineEPS 1e-9intNum;Charch[ -];//const int INF=0X7FFFFFFF; //нчоч╢сConst intinf=0x3f3f3f3f;/*inline void P (int x) {num=0;if (!x) {Putchar (' 0 ');p UTS (""); return;}    while (x>0) ch[++num]=x%10,x/=10;    while (Num) Putchar (ch[num--]+48); Puts ("");}*/inline ll read () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;} InlinevoidPintx) {Num=0;if(!x) {Putchar ('0');p UTS ("");return;}  while(x>0) ch[++num]=x%Ten, x/=Ten;  while(Num) Putchar (ch[num--]+ -); Puts ("");}//**************************************************************************************Const intN =500000, M =500000;intKey[m], head[n], next[m], CNT;intA[n], p[n], ans[n];BOOLV[n];inlinevoidAddConst int& X,Const int&y) {key[cnt]=y; NEXT[CNT]=Head[x]; HEAD[X]= cnt + +;} InlineintFintx) {returnP[X] = = x? X:P[X] =F (p[x]);}intMain () {intN, M;memset (head,-1,sizeofhead); scanf ("%d%d", &n, &m);  for(inti =1, A, B; I <= m; i + +) scanf ("%d%d", &a, &b), add (A, B), add (b, a);intK; scanf ("%d", &k);  for(inti =1; I <= K; i + +) scanf ("%d", &a[i]), v[a[i]] =true;  for(inti =1; I <= N; i + +) P[i]=i; intz = n-K;  for(inti =0; I < n; i + +)        if(!V[i]) for(intj = Head[i]; ~ J; j =Next[j])if(!V[key[j]])if(F (i)! =F (Key[j])) p[f (i)]= F (Key[j]), Z--; Ans[k+1] =Z;  for(inti = k; I >=1; I--) {V[a[i]]=false; Z++;  for(intj = Head[a[i]]; ~ J; j =Next[j])if(!V[key[j]])if(F (a[i])! =F (Key[j])) p[f (A[i] )= F (Key[j]), Z--; Ans[i]=Z; }     for(inti =1; I <= K +1; i + +) printf ("%d\n", Ans[i]); return 0;}

Bzoj 1015: [JSOI2008] Star Wars Starwar and check set

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.