# Rokua P2860 [Usaco06jan] Redundant path redundant Paths (Tarjan for dual unicom components)

Source: Internet
Author: User

Title 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.

In order to walk from one of the 1≤f≤5000 Meadows to another, Bessie and her companions sometimes had to pass through some horrible trees they hated. Cows are tired of being forced to take a certain route, so they want to build new roads so that there will be at least two separate paths between each pair of pastures, so that they have more choices.

There is already at least one path between each pair of pastures. Give a description of all R (f-1≤r≤10000) bidirectional roads, each connecting two different pastures, calculate the minimum number of new roads, and the paths are connected by a number of roads. Two paths are separated from each other, which means that there is no coincident path for the two paths. However, two separate paths can have some of the same pastures. There may be two different paths between the same pair of pastures, and you can build another road between them as a different road.

Input/output format

Input format:

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 format:

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

Input and Output sample input sample #: Copy
`7 71 22 33 42 54 55 65 7`
Output Example # #: Replication
`2`
Description

Explanation of the sample:

One visualization of the paths is:

1 2 3

+---+---+

``   |   |   |   |``

6 +---+---+ 4

/5//7 +building new paths from 1 to 6 and from 4 to 7 satisfies the conditions.

1 2 3

+---+---+

:

6 +---+---+ 4

/5:/:

/ :

7 +----Check Some of the routes:

1–2:1–> 2 and 1–> 6–> 5–> 2

1–4:1–> 2–> 3–> 4 and 1–> 6–> 5–> 4

3–7:3–> 4–> 7 and 3–> 2–> 5–> 7

Every pair of fields are, in fact, connected by and routes.

It's possible that adding some other path would also solve the problem (like one from 6 to 7). Adding paths, however, is the minimum.

First of all, we don't have to think about the points in the double-unicom component.

So we're going to use Tarjan to shrink the double-link component.

That way, it's bound to form a tree.

Next consider greed, for any of the three not in the same dual-component and the only point in the degree

We have an edge between them, so it must be optimal.

So we just need to count the 1-in point.

The final answer is \$ (ans+1)/2\$

`//Luogu-judger-enable-o2#include <cstdio>#include<cstring>#include<algorithm>#include<stack>#defineGetChar () (s = = t && (t = (s = bb) + fread (BB, 1, 1 << stdin), s = = t)? EOF: *s++)Charbb[1<< the], *s = BB, *t =BB;using namespacestd;Const intmaxn=1e5+Ten; inlineintRead () {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;}structnode{intU,V,W,NXT;} EDGE[MAXN];inthead[maxn],num=1; inlinevoidAddedge (intXinty) {edge[num].u=x; EDGE[NUM].V=y; EDGE[NUM].NXT=Head[x]; HEAD[X]=num++;}intdfn[maxn],low[maxn],vis[maxn],tot=0, colornum=0, COLOR[MAXN],INDER[MAXN];intfuck;stack<int>s;voidTarjan (intNowintFA) {Dfn[now]=low[now]=++tot;    S.push (now); Vis[now]=1;  for(inti=head[now];i!=-1; i=edge[i].nxt) {        if(!dfn[edge[i].v]&&edge[i].v!=FA) Tarjan (Edge[i].v,now), Low[now]=min (low[now],low[edge[i].v]); if(VIS[EDGE[I].V]&AMP;&AMP;EDGE[I].V!=FA) low[now]=min (low[now],dfn[edge[i].v]); }    if(dfn[now]==Low[now]) {        intH=0; Colornum++;  Do{h=S.top (); COLOR[H]=Colornum;        S.pop (); } while(h!=Now ); }}intMain () {#ifdef WIN32 freopen ("a.in","R", stdin); #else    #endifmemset (Head,-1,sizeof(head)); intN=read (), m=read ();  for(intI=1; i<=m;i++)    {        intX=read (), y=read ();        Addedge (x, y);    Addedge (Y,X); } Tarjan (1,0);  for(intI=1; i<=num-1; i++)         if(color[edge[i].u]!=color[edge[i].v]&&fuck[edge[i].u][edge[i].v]==0) FUCK[EDGE[I].U][EDGE[I].V]=1, Inder[color[edge[i].u]]++, INDER[COLOR[EDGE[I].V]]++; intans=0;  for(intI=1; i<=colornum;i++)        if(inder[i]==2)//bidirectional Edgeans++; printf ("%d", (ans+1) >>1); return 0;}`

Rokua P2860 [Usaco06jan] Redundant path redundant Paths (Tarjan for dual-component)

Related Keywords:
Related Article

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.