poj3177 && poj3352 Edge Two-connected component pinch point

Source: Internet
Author: User

Redundant Paths
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 12676 Accepted: 5368

Description

In order to get from one of the F (1 <= f <= 5,000) grazing fields (which is numbered 1..F) to another field, Bessi E and the rest of the herd is forced to cross near the Tree of rotten Apples. The cows is now tired of often being forced to take a particular path and want to build some new paths so that they would Always has a choice of at least, separate routes between any pair of fields. They currently has at least one route between each pair of fields and want to has at least. Of course, they can only travel on official Paths when they move from one field to another.

Given a description of the current set of R (F-1 <= R <=) paths This each connect exactly both different field s, determine the minimum number of new paths (each of the which connects exactly.) that must is built so that there is at least, separate routes between any pair of fields. Routes is considered separate if they use none of the same paths, even if they visit the same intermediate field along th e-To.

There might already be more than one paths between the same pair of fields, and your may also build a new path that connect s the same fields as some and other path.

Input

Line 1:two space-separated integers:f and R

Lines 2..r+1:each line contains, space-separated integers which is the fields at the endpoints of some path.

Output

Line 1: A single integer which is the number of the new paths this must be built.

Sample Input

7 71 22 33 42 54 55 65 7

Sample Output

2 Test instructions: give you a picture without a direction, judging at least how many sides to add, in order to make any 2 points between at least 2 independent (no common edge) of the road; train of thought: the point in the same double connected component can be equivalent to a point, the original image becomes a tree, then the problem is converted into a tree and how many edges can become a double connected graph. Answer = (the number of sides of the tree with a degree of 1 + 1)/2;
/** author:sweat123 * Created time:2016/6/21 20:07:00 * File Name:main.cpp*/#include<Set>#include<map>#include<queue>#include<stack>#include<cmath>#include<string>#include<vector>#include<cstdio>#include<time.h>#include<cstring>#include<iostream>#include<algorithm>#defineINF 1<<30#defineMOD 1000000007#definell Long Long#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1#definePi ACOs (-1.0)using namespacestd;Const intMAXN =5010;structnode{intto ; intNext; }EDGE[MAXN<<2];intPre[maxn],vis[maxn],pa[maxn],dfn[maxn],low[maxn],n,m,ind;intPX[MAXN],PY[MAXN];intpcnt;voidAddintXinty) {edge[ind].to=y; Edge[ind].next=Pre[x]; PRE[X]= ind + +; }intFindintx) {    if(pa[x]! = x) Pa[x] =find (pa[x]); returnPa[x]; }voidDfsintRtintKintFA) {Dfn[rt]= Low[rt] =K;  for(inti = Pre[rt]; I! =-1; i =Edge[i].next) {        intt =edge[i].to; if(!dfn[t] && t! =FA) {DFS (t,k+1, RT); LOW[RT]=min (low[rt],low[t]); if(Low[t] >Dfn[rt]) {px[pcnt]= rt,py[pcnt++] =T; } Else {                intFX =find (t); intFY =find (RT); if(PA[FX]! =Pa[fy]) {PA[FX]=fy; }            }         } Else if(t! = FA) {//Bridge is differenet from pointLOW[RT] =min (low[rt],dfn[t]); }    }   }intD[MAXN],F[MAXN];intMain () { while(~SCANF ("%d%d",&n,&m)) {IND=0; Pcnt=0; memset (PRE,-1,sizeof(pre));  for(inti =1; I <= m; i++){            intx, y; scanf ("%d%d",&x,&y);        Add (x, y), add (y,x); }           for(inti =1; I <= N; i++) {Pa[i]=i; } memset (DFN,0,sizeof(DFN)); memset (Low,0,sizeof(low)); DFS (1,1,-1); //for (int i = 1; I <= n; i++) {//cout<<dfn[i]<< ' <<low[i]<<endl; //}        //cout<<endl;memset (D,0,sizeof(d)); Memset (F,-1,sizeof(f)); intPnum =0;  for(inti =1; I <= N; i++){            intFX =find (i); if(F[FX] = =-1) F[FX] = + +Pnum; F[i]=F[FX]; }         for(inti =0; i < pcnt; i++) {D[f[px[i] ]++,d[f[py[i]] + +; }        intAns =0;  for(inti =1; I <= pnum; i++){            if(D[i] = =1) ans + +; } printf ("%d\n", (ans +1) /2); }    return 0;}

poj3177 && poj3352 Edge Two-connected component 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.