POJ 3352 Road Construction "side double connectivity for the minimum plus how many edges make the diagram double connect && pinch point"

Source: Internet
Author: User

Road Construction
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 10141 Accepted: 5031

Description

It's almost summer time, and that means it ' s almost summer construction time! This year, the good people who is in charge of the roads on the tropical island paradise of "Remote" would like to R Epair and upgrade the various roads that leads between the various tourist attractions on the island.

The roads themselves is also rather interesting. Due to the strange customs of the island, the roads is arranged so then they never meet at intersections, but rather pass Over or under each of the other using bridges and tunnels. The This is the road runs between, specific tourist attractions, so that the tourists does not become irreparably lost.

Unfortunately, given the nature of the repairs and upgrades needed on each road while the construction company works on a Particular road, it's unusable in either direction. This could cause a problem if it becomes impossible to travel between the tourist attractions, even if the construction Co Mpany works on only one road at any particular time.

So, the Road Department of Remote have decided to call upon your consulting services to help remedy this problem. It has been decided, that new roads would, and is built between the various attractions in such a-the-in-the-final C Onfiguration, if any one road is undergoing construction, it would still being possible to travel between any and tourist att Ractions using the remaining roads. Your task is to find the minimum number of new roads necessary.

Input

The first line of input would consist of positive integers n and R, separated by a space, where 3≤ n ≤1000 is the number of tourist attractions on the island, and 2≤ R ≤1000 is the number of roads. The tourist attractions is conveniently labelled from 1 toN. Each of the following R lines would consist of the integers, v and W, separated by a space, Indi Cating that a road exists between the attractions labelled v and W. Note that the either direction down each road, and any pair of tourist attractions would has at the most one Roa D directly between them. Also, you were assured the current configuration, it was possible to travel between any and tourist attractions.

Output

One line, consisting of a integer, which gives the minimum number of roads that we need to add.

Sample Input

Sample Input 121 94 109 10Sample Input 23 31 22 31 3.

Sample Output

Output for sample input 12Output for sample input 20

Test instructions: There are n tourist attractions and R Road, any of the two attractions are connected indirectly or directly, but sometimes the road construction we can not go this way, that is to say, the road between the two attractions is broken, ask now to add at least how many channels, so that any two attractions between more than one channel

The problem: It is obvious that the question is to add at least how many roads to connect the diagram, because all the points are connected, but not double-connected, we can think of the original data as a two-connected graph minus a few edges into the graph, now we need to add these several sides, a double-connected graph whose degrees are at least 2, So when we meet a point with a degree of 1, the total number of points with the last degree 1 (sum+1)/2 is the final result.

Note: Input output True pit, would have thought that each set of input and output before the output string results have been WA


#include <stdio.h> #include <string.h> #include <stack> #include <algorithm> #define MAX 21000# include<vector> #define MAXM 2001000#define INF 0x7ffffffusing namespace Std;int n,m,num,bridge;int Head[MAX],ans ; int in[max];int low[max],dfn[max];int instack[max],iscut[max];int addbcc[max];int dfsclock,bccno[max];int bcccnt; Stack<int>s;vector<int>newmap[max];vector<int>bcc[max];struct node{int Beg,end,next;} Edge[maxm];void init () {Ans=0;memset (head,-1,sizeof (Head));} void Add (int u,int v) {edge[ans].beg=u;edge[ans].end=v;edge[ans].next=head[u];head[u]=ans++;} void Getmap () {int A,b,i;while (m--) {scanf ("%d%d", &a,&b); add (b); add (b,a);}} void Tarjan (int u,int fa) {int i,j,v;s.push (u); instack[u]=1;low[u]=dfn[u]=++dfsclock;int son=0;int flag=1;for (i=head[ U];i!=-1;i=edge[i].next) {v=edge[i].end;if (V==fa&&flag)//go to heavy side {flag=0;continue;} if (!dfn[v]) {Tarjan (v,u); Low[u]=min (Low[u],low[v]); if (Low[v]>dfn[u])//Is bridge bridge++;} else Low[u]=min (LOW[U],DFN[V]);}    if (Low[u]==dfn[u]) {bcccnt++;    while (1) {v=s.top ();    S.pop ();    instack[v]=0;    bccno[v]=bcccnt;    if (v==u) break; }}}void Find (int l,int r) {int I;memset (low,0,sizeof (Low)); Memset (Dfn,0,sizeof (DFN)); Memset (Instack,0,sizeof ( Instack) memset (iscut,0,sizeof (iscut));d fsclock=bcccnt=0;for (i=l;i<=r;i++) {if (!dfn[i]) Tarjan (i,-1);}} void Suodian () {int U,v,i;memset (in,0,sizeof (in)), for (i=0;i<ans;i+=2) {U=bccno[edge[i].beg];v=bccno[edge[i].end ];if (v!=u) {newmap[u].push_back (v); Newmap[v].push_back (u); in[u]++;in[v]++;}}} void Solve () {int sum,i,j;sum=0;for (i=1;i<=bcccnt;i++) {if (in[i]==1) sum++;} printf ("%d\n", (sum+1)/2);} int main () {int i,j,k,t;k=1;while (scanf ("%d%d", &n,&m)!=eof) {init (); Getmap (); find (1,n); Suodian (); Solve ();} return 0;}

  

POJ 3352 Road Construction "side double connectivity for the minimum plus how many edges make the diagram double connect && pinch point"

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.