1015: [JSOI2008] Star Wars Starwar

Source: Internet
Author: User

1015: [JSOI2008] Star Wars Starwar time limit:3 Sec Memory limit:162 MB
submit:3001 solved:1321
[Submit] [Status] Description

Long ago, in a distant galaxy, a dark empire was leaning against its super-weapons rulers 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 Input8 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
7Sample Output1
1
1
2
3
3HINT Source

The puzzle: As JSZKC god Ben said-since the collection can not be merged, then the inverted insert is not OK? So I did it for a bit, and the result was 70 points, TLE ... Then I had to find the online standard, the results found that people in and check the set inside there is an unusually strong optimization (see the program inside the Getfat function), and then rub wildest ac ... The way to do this--first, all the edges are not related to the deletion of all the merge, and then in the order of the deleted point inverted to merge, which every time to record the number of connected blocks ... (Note: The final output should be-i+1, because if for example, all the planets in the final data are killed, then if the simple is connected to the block, there should be N is, but the fact that a planet is not ... )
1 typePoint=^node;2Node=Record3 G:longint;4 Next:point;5      End;6 var7 I,j,k,l,m,n,t:longint;8A:Array[0..400000] ofPoint ;9C,b,d,e:Array[0..400000] ofLongint;Ten P:point; One functionGetfat (x:longint): Longint;inline; A          begin -               ifX&LT;&GT;C[X] Then -                  begin theC[x]:=getfat (C[x]); //optimization of Orz's toughness -                  End; - exit (C[x]); -          End; + functiontog (x,y:longint): Boolean;inline; -          begin +Exit (Getfat (x) =Getfat (y)); A          End; at proceduremerge (X,y:longint), inline; -           begin -C[getfat (x)]:=Getfat (y); -           End; - procedureAdd (x,y:longint); inline; -           varP:point; in           begin - new (p); top^.g:=y; +p^.next:=A[x]; -a[x]:=p; the           End; * begin $ readln (n,m);Panax Notoginseng       fori:=1  toN Do -          begin thec[i]:=i; +a[i]:=Nil; A          End; the       fori:=1  toM Do +          begin - readln (j,k); $Add (j+1, K +1); Add (k +1, j+1); $          End; -Fillchar (b,sizeof (b),0); - readln (t); the       fori:=1  toT Do -          beginWuyi readln (D[i]); thed[i]:=d[i]+1; -b[d[i]]:=1; Wu          End; -l:=N; About       fori:=1  toN Do $          begin -               ifb[i]=0  Then -                  begin -p:=A[i]; A                        whileP<>Nil  Do +                             begin the                                  ifb[p^.g]=0  Then -                                     begin $                                          if  not(Tog (I,P^.G)) Then the                                             begin the Dec (l); merge (I,P^.G); the                                             End; the                                     End; -p:=P^.next; in                             End; the                  End; the          End; Aboute[t+1]:=l; the       forI:=tDownto 1  Do the          begin theb[d[i]]:=0; +p:=A[d[i]]; -                whileP<>Nil  Do the                     beginBayi                          ifb[p^.g]=0  Then the                             begin the                                  if  not(Tog (D[I],P^.G)) Then -                                     begin - merge (D[I],P^.G); the Dec (l); the                                     End; the                             End; thep:=P^.next; -                     End; thee[i]:=l; the          End; the       fori:=1  tot+1  DoWriteln (e[i]-i+1);94 End.

1015: [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.