BZOJ1015[JSOI2008] Star Wars starwar[and collection]

Source: Internet
Author: User

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

Long ago, in a distant galaxy, a dark empire was leaning against its super-weapons rulers throughout the galaxy. One day, with an accidental
Opportunity, a rebel army destroyed the empire's super weapons and attacked almost all the planets in the galaxy. These planets are directly connected to each other through special etheric tunnels.
Connected to or indirectly. 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 have plans
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 army's first
I'll give you a mission: provide an Ethernet tunnel connection between the original two planets and the Order of the empire-hit planets to find out every
The number of connected fast planets that the rebels occupy after a strike. (If two planets can be connected directly or indirectly through the 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 planet's
Number and number of Ethernet 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 that there is an "ether" tunnel between Planet X and Planet Y that can communicate directly. The next behavior is an integer k, which indicates that the planet that will be attacked
Number. The next K-line, each line has an integer, in order to list the attack target of the imperial army. The number of k is different, and all the 0 to n-1
In the surrounding.

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 existing planet after the strike
Number of connected blocks.

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
3

And check set does not support deletion, so backwards processing, each join a point

Use Tot to record the number of connected blocks, without adding a point on the + 1, encountered two merges 1, the point will not be destroyed by adding the method

Plus one point is to facilitate all sides of it

/************************************************************** problem:1015 user:thwfhk language:c++ Res ult:accepted time:1284 Ms memory:13788 kb****************************************************************/ ////main.cpp//bzoj1015////Created by Candy on 9/17/16.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespacestd;Const intn=4e5+5, m=2e5+5;intRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; C=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; C=GetChar ();} returnx*F;}structedge{intV,ne;} E[m<<1];intH[n],cnt=0; inlinevoidInsintUintv) {CNT++; E[CNT].V=v;e[cnt].ne=h[u];h[u]=CNT; CNT++; E[CNT].V=u;e[cnt].ne=h[v];h[v]=CNT;} intn,m,x,y,k,tot=0, ans[n];intHas[n],lst[n],vis[n];//vis for ins from 0intFa[n];intFindintx) {returnx==fa[x]?x:fa[x]=find (Fa[x]);} InlinevoidMergeintXinty) {    intF1=find (x), f2=find (y); if(F1!=F2) fa[f1]=f2,tot--;}voidAddintu) {     for(intI=h[u];i;i=e[i].ne) {        intv=e[i].v; if(Vis[v]) merge (U,V); }}intMainintargcConst Char*argv[]) {N=read (); m=read ();  for(intI=1; i<=m;i++) {x=read () +1; Y=read () +1; ins (x, y); } k=read ();  for(intI=1; i<=n;i++) has[i]=1, fa[i]=i;  for(intI=1; i<=k;i++) {x=read () +1; HAS[X]=0; Lst[i]=x; }          for(intu=1; u<=n;u++)        if(Has[u]) {tot++;            Add (u); Vis[u]=1; } ans[k+1]=tot;  for(inti=k;i>=1; i--) {tot++;        Add (Lst[i]); Vis[lst[i]]=1; Ans[i]=tot; }     for(intI=1; i<=k+1; i++) printf ("%d\n", Ans[i]); return 0;}

BZOJ1015[JSOI2008] Star Wars starwar[and collection]

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.