[And look up the set] JSOI2008 Star Wars

Source: Internet
Author: User

Title 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/output format

Input format:

The first line of the input file contains two integers, NN (1 < = N < = 2M) and MM (1 < = M < = 200,000), respectively, indicating the number of planets and the number of etheric tunnels. The planet is numbered with an integer of 0 ~ N-1.

The next M-line, each line consists of two integers X, y, where (0 < = X <> Y means there is an "ether" tunnel between the planet XX and the Star yy, which can be communicated directly.

The next behavior is an integer k, which represents the number of planets that will be hit.

The next K-line, each line has an integer, in order to list the attack target of the imperial army. The k numbers are different and are within the range of 0 to n-1.

Output format:

The first line is the number of connected blocks at the beginning of the planet. The next K-line, an integer per line, indicates the number of connected blocks of the existing planet after the strike.

Input/Output sample

Input Sample # #:

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

Sample # # of output:

1
1
1
2
3
3

Description

[JSOI2008]

Exercises

It's also a question of using and checking the set.

See in the title description each time will attack a point, this point and its adjacent edge will disappear, but the check set does not support delete operations, how to do?

We can reverse the process, first put all the points of the attack marked, and then sweep all the points, the unmarked point of the map, of course, this figure is not necessarily connected, that is, the possible remaining points of the set of more than one connected block, and this fast connection is the number of K attacks after the amount of connected blocks, save it, And then backwards processing, that is, for (i=k~1) to add the point I delete, and then to count the number of connected blocks, which is the answer after the i-1 attack, especially when I=1, Ans[i-1] is the first to save the number of connected blocks that were not attacked

#include <bits/stdc++.h>#define IN (i) (I=read ())using namespaceStdintRead () {intans=0, f=1;CharI=getchar (); while(i<' 0 '|| I>' 9 '){if(i=='-') f=-1;    I=getchar (); } while(i>=' 0 '&& i<=' 9 ') {ans= (ans<<1) + (ans<<3) +i-' 0 ';    I=getchar (); }returnAns*f;}intN,m,k;intLenintfa[400010];structEDGEC {intFrom,to,next;} e[4000010];inthead[400010];intvis[400010],ans[400010],h[400010];voidAddintAintb) {e[++len].to=b;    E[len].from=a;    E[len].next=head[a]; Head[a]=len;}intFindintx) {if(fa[x]!=x) Fa[x]=find (fa[x]);returnFA[X];}intMain () {in (n); in (m); for(intI=0; i<n;i++) fa[i]=i; for(intI=1; i<=m;i++) {intb;        In (a); in (b);        Add (A, b);    Add (B,a); } in (k); for(intI=1; i<=k;i++) {intX;in (x); vis[x]=1;    H[i]=x; }intTot=n-k; for(intI=1; i<=2*m;i++) {intx=e[i].from,y=e[i].to;if(!vis[x] &&!vis[y]) {intFx=find (x), Fy=find (y);if(FX!=FY)                {tot--;            Fa[fx]=fy; }}} Ans[k+1]=tot; for(intt=k;t>=1; t--) {intU=H[T]; vis[u]=0; tot++; for(intI=head[u];i;i=e[i].next) {intto=e[i].to;intX=find (U), Y=find (to);if(!vis[to] && x!=y)                {tot--;            Fa[x]=y;    }} Ans[t]=tot; } for(intI=1; i<=k+1; i++) {cout<<ans[i]<<endl; }return 0;}

[And look up the set] JSOI2008 Star Wars

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.