ZOJ2588. Burning bridges--side Double connected component, with heavy edge

Source: Internet
Author: User

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1588

Title Description:
The Ferry Kingdom is a beautiful island nation, with a total of N islands and M-bridges, which can be reached on any island from every small island. Unfortunately, the ferry kingdom was recently conquered by Jordan. Jordan decided to burn down all the bridges. It was a cruel decision, but Jordan's advisers advised him not to do so, because if all the bridges were burnt, his own army would not be able to reach another island from one island. So Jordan decided to burn as many bridges as possible, as long as he could make sure that his army could reach every island from any small island.
Now the people of the ferry kingdom would like to know which bridges will be burnt down. Of course, they are unable to know this information, because which bridges will be burned is Jordan's military secrets. However, you can tell the people of the ferry kingdom which bridges will certainly not be burnt.

Analysis:
The problem is to remove the edge of the two connected components of some side, so that the original or connected, then which side must not be deleted? It must be a bridge.

But this problem has a heavy edge, let's consider the impact of the heavy side:
1. For the strong connected component of the graph, the heavy edge is not affected, because the strong connectivity only requires any two points can be interconnected

2. For the point of the undirected graph of the two-connected components , the heavy edge is also not affected, because the point of dual connectivity requirements are any two points between any two points do not repeat the path, the duplication of the edge is not required

3. For the undirected graph of the side of the double-connected component , the heavy edge has an impact, because the edge of the double connectivity requires at least two edges between any two points of the non-repeating path

Well, for the heavy side, it's definitely not a bridge.
For example, there are two sides (Tarjan), if the heavy edge is not processed, then the exit is the bridge, obviously, this is wrong

So all we have to do is record the heavy edges as we enter the edges.

In addition to the non-graph Dfs tree only the tree edge and the back edge, and there is no forward edge and cross-border, I am on the web for those who seek the non-graph of the point double and edge double template feel very strange (...) Superfluous

//c++ 610 3652#include <cstring>#include <cstdio>#include <iostream>#include <set>#include <map>#include <vector>#include <functional>#include <algorithm>#define REP (i,n) for (int i=0;i< (n); ++i)#define REP1 (I,A,B) for (int i=a;i< (b); ++i)#define FOR (i,n) for (int i=0;i<= (n); ++i)#define FOR1 (I,A,B) for (int i=a;i<= (b); ++i)#define CLR (a) memset (A,0,sizeof (a))Const intmaxn=10010;Const intmaxm=100010;using namespace STD;intN,m;intLOW[MAXN],DFN[MAXN],STACK[MAXN];intDfs_clock,top,bridge,block;BOOLISBRIDGE[MAXM];structedge{intTo,next;intTag,id;} edge[maxm<<1];intHead[maxn],tot;voidAddedge (intUintVintID) {edge[tot].to=v;edge[tot].tag=0; edge[tot].id=id;edge[tot].next=head[u];head[u]=tot++;}voidInit () {tot=0;memset(Head,0xFF,sizeof(head));}inline BOOLIshash (intUintV) {intVn for(inti=head[u];i!=-1; i=edge[i].next) {vn=edge[i].to;if(VN==V) {edge[i].tag++;return false; }    }return true;}voidDfsintUintPre) {intV    Low[u]=dfn[u]=++dfs_clock; Stack[top++]=u; for(inti=head[u];i!=-1; i=edge[i].next) {v=edge[i].to;if(V==pre)Continue;if(!dfn[v]) {DFS (V,U);if(Low[u]>low[v]) low[u]=low[v];if(Low[v]>dfn[u]&&!edge[i].tag)                {bridge++; isbridge[edge[i].id]=true; }        }Else if(Low[u]>dfn[v]) low[u]=dfn[v]; }}intMain () {#ifndef Online_judgeFreopen ("In.cpp","R", stdin);#endif //Online_judge     intT,u,v;scanf("%d", &t); while(t--) {scanf("%d%d", &n,&m);        Init ();        CLR (Isbridge); Rep (i,m) {scanf("%d%d", &u,&v);if(Ishash (U,V)) {Addedge (u,v,i+1); Addedge (v,u,i+1);        }} CLR (DFN); Dfs_clock=top=block=bridge=0; Dfs1,-1);printf("%d\n", bridge);intK=bridge; For1 (I,1, m) {if(Isbridge[i]) {printf("%d", i);if(--k)printf(" "); }        }if(bridge)puts("");ifTputs(""); }return 0;}

ZOJ2588. Burning bridges--side Double connected component, with heavy edge

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.