POJ 3177 Redundant Paths
来源:互联网 发布:淘宝开店需要保证金吗 编辑:程序博客网 时间:2024/05/22 16:00
Description
In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples. The cows are now tired of often being forced to take a particular path and want to build some new paths so that they will always have a choice of at least two separate routes between any pair of fields. They currently have at least one route between each pair of fields and want to have at least two. 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 <= 10,000) paths that each connect exactly two different fields, determine the minimum number of new paths (each of which connects exactly two fields) that must be built so that there are at least two separate routes between any pair of fields. Routes are considered separate if they use none of the same paths, even if they visit the same intermediate field along the way.
There might already be more than one paths between the same pair of fields, and you may also build a new path that connects the same fields as some other path.
Given a description of the current set of R (F-1 <= R <= 10,000) paths that each connect exactly two different fields, determine the minimum number of new paths (each of which connects exactly two fields) that must be built so that there are at least two separate routes between any pair of fields. Routes are considered separate if they use none of the same paths, even if they visit the same intermediate field along the way.
There might already be more than one paths between the same pair of fields, and you may also build a new path that connects the same fields as some other path.
Input
Line 1: Two space-separated integers: F and R
Lines 2..R+1: Each line contains two space-separated integers which are the fields at the endpoints of some path.
Lines 2..R+1: Each line contains two space-separated integers which are the fields at the endpoints of some path.
Output
Line 1: A single integer that is the number of new paths that must be built.
Sample Input
7 71 22 33 42 54 55 65 7
Sample Output
2
Hint
Explanation of the sample:
One visualization of the paths is:
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 is, in fact, connected by two routes.
It's possible that adding some other path will also solve the problem (like one from 6 to 7). Adding two paths, however, is the minimum.
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 is, in fact, connected by two routes.
It's possible that adding some other path will also solve the problem (like one from 6 to 7). Adding two paths, however, is the minimum.
Source
USACO 2006 January Gold
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
双连通分量裸题~
被昨天上午的考试坑得很惨,直接交上无重边的,WA到飞起,后来才想起来要去重边,这个程序应该是很久以前刚讲双连通分量的时候写的。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int VM=5010;const int EM=10010;struct Edge{ int to,nxt;}edge[EM<<1];int head[VM],vis[VM],dfn[VM],low[VM];int n,k,cnt;void addedge(int cu,int cv){ edge[cnt].to=cv; edge[cnt].nxt=head[cu]; head[cu]=cnt++;}void Tarjan(int u,int fa){ vis[u]=1; dfn[u]=low[u]=++k; for(int i=head[u];i!=-1;i=edge[i].nxt){ int v=edge[i].to; if(vis[v]==1 && v!=fa) low[u]=min(low[u],dfn[v]); if(!vis[v]){ Tarjan(v,u); low[u]=min(low[u],low[v]); } } vis[u]=2;}int main(){ int m; int deg[VM]; while(~scanf("%d%d",&n,&m)){ memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(deg,0,sizeof(deg)); cnt=0; int u,v; while(m--){ scanf("%d%d",&u,&v); if(head[u]!=-1 && edge[head[u]].to==v) continue; addedge(u,v); addedge(v,u); } k=0; Tarjan(1,1); for(u=1;u<=n;u++) for(int i=head[u];i!=-1;i=edge[i].nxt){ v=edge[i].to; if(low[u]!=low[v]) deg[low[u]]++; } int left=0; for(int i=1;i<=n;i++) if(deg[i]==1) left++; printf("%d\n",(left+1)>>1); } return 0;}
0 0
- POJ 3177 Redundant Paths
- poj 3177 Redundant Paths
- poj 3177 Redundant Paths
- POJ 3177 Redundant Paths
- poj 3177 Redundant Paths
- poj 3177 Redundant Paths
- *POJ 3177 Redundant Paths**
- poj 3177 Redundant Paths
- Redundant Paths POJ, 3177
- POJ 3177 Redundant Paths
- POJ 3177 Redundant Paths
- POJ 3177 Redundant Paths
- poj 3177 Redundant Paths
- poj 3177 Redundant Paths
- POJ,3177 Redundant Paths
- POJ 3177 Redundant Paths
- poj 3177 Redundant Paths
- poj 3177 Redundant Paths tarjan
- codeforces 589d(相遇问题)
- 分享| Go语言(golang)的认识,跟学习资料及其开发工具
- 【u119】中位数
- Scala 提取器与注解深度解析之编程进阶(6)
- 欢迎使用CSDN-markdown编辑器
- POJ 3177 Redundant Paths
- poj3669【bfs】
- 九大排序算法之代码实现
- CodeForces 55D Beautiful numbers(数位dp)
- POJ 1125 Stockbroker Grapevine
- mysql默认连接超时问题的解决方法
- mac下eclipse配置tomcat
- (三十)、Collection接口
- 读《About Face 4 交互设计精髓》4