Redundant Paths-POJ3177(强连通缩点)
http://poj.org/problem?id=3177
题目大意:给你几个点和几条边 求你能加几条边 就可以让每一个点到达任意点都有两种方法。
Description
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
Lines 2..R+1: Each line contains two space-separated integers which are the fields at the endpoints of some path.
Output
Sample Input
7 7
1 2
2 3
3 4
2 5
4 5
5 6
5 7
Sample Output
2
Hint
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.
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector> using namespace std;
#define N 20000 int low[N],dfn[N],n,fa[N],Stack[N],belong[N],Is[N],aa[N];
int Time,top,ans;
vector<vector <int> >G; void Inn()
{
G.clear();
G.resize(n+);
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(fa,,sizeof(fa));
memset(belong,,sizeof(belong));
memset(Stack,,sizeof(Stack));
memset(Is,,sizeof(Is));
memset(aa,,sizeof(aa));
Time=top=ans=;
} void Tarjin(int u,int f)
{
dfn[u]=low[u]=++Time;
Stack[top++]=u;
Is[u]=;
fa[u]=f;
int len=G[u].size(),v;
for(int i=; i<len; i++)
{
v=G[u][i];
if(!dfn[v])
{
Tarjin(v,u);
low[u]=min(low[u],low[v]);
}
else if(f!=v)
low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u])
{
ans++;
do
{
v=Stack[--top];
belong[v]=ans;
Is[v]=;
}while(v!=u);
}
} int main()
{
int m,a,b,i,sum;
while(scanf("%d %d",&n,&m)!=EOF)
{
sum=;
Inn();
for(i=;i<=m;i++)
{
scanf("%d %d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
for(i=;i<=n;i++)
{
if(!dfn[i])
Tarjin(i,);
}
for(i=;i<=n;i++)
{
int v=fa[i];
if(belong[i]!=belong[v]&&v!=)
{
aa[belong[i]]++;
aa[belong[v]]++;
}
}
for(i=;i<=ans;i++)
{
if(aa[i]==)
sum++;
}
printf("%d\n",(sum+)/);
}
return ;
}
Redundant Paths-POJ3177(强连通缩点)的更多相关文章
- POJ3177 Redundant Paths —— 边双联通分量 + 缩点
题目链接:http://poj.org/problem?id=3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total ...
- [POJ3177]Redundant Paths(双联通)
在看了春晚小彩旗的E技能(旋转)后就一直在lol……额抽点时间撸一题吧…… Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Tota ...
- poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11047 Accepted: 4725 ...
- POJ3177 Redundant Paths 双连通分量
Redundant Paths Description In order to get from one of the F (1 <= F <= 5,000) grazing fields ...
- POJ3177:Redundant Paths(并查集+桥)
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19316 Accepted: 8003 ...
- 缩点【洛谷P2860】 [USACO06JAN]冗余路径Redundant Paths
P2860 [USACO06JAN]冗余路径Redundant Paths 为了从F(1≤F≤5000)个草场中的一个走到另一个,贝茜和她的同伴们有时不得不路过一些她们讨厌的可怕的树.奶牛们已经厌倦了 ...
- POJ 3177 Redundant Paths(边双连通的构造)
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13717 Accepted: 5824 ...
- [双连通分量] POJ 3177 Redundant Paths
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13712 Accepted: 5821 ...
- tarjan算法求桥双连通分量 POJ 3177 Redundant Paths
POJ 3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12598 Accept ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
随机推荐
- 锐动SDK针对游戏直播提出的解决方案
方案架构 PC端视频直播与录播功能为游戏厂商宣传,玩家个人秀,大型电竞赛事提供完美的技术解决方案. 直播形式灵活多变不,同音源的选择,画面切换,游戏中嵌入摄像头丰,富解说画面.突出主播个人魅力与粉丝形 ...
- 掌握Spark机器学习库-07-随机梯度下降
1)何为随机梯度下降 优化方法 迭代更新,来寻找函数全局最优解的方法 与最小二乘法相比:适用于变量众多,模型更复杂 2)梯度 变化最快,“陡峭” 通过函数表达式来衡量梯度 3)随机梯度下降原理推导过程 ...
- 什么是BDD?
BDD是TDD的一种衍生,通过特定的BDD框架,用自然语言或类自然语言,按照编写用户故事或者用户用例的方式,以功能使用者的视角,描述并编写测试用例. BDD源于TDD并优于测试驱动开发. 之所以说BD ...
- Sass的的使用二
1.嵌套输出方式 nested Sass 提供了一种嵌套显示 CSS 文件的方式.例如 nav { ul { margin: 0; padding: 0; list-style: none; } li ...
- 【java_设计模式】建造者模式
应用场景对生成对象进行链式配置好处:按需配置对象,灵活修改默认配置,比构造方法创建对象更直观. public static void init() {if (okHttpClient == null) ...
- Oracle11g 审计介绍
审计是记录数据库上方方面面操作.事件等信息,是数据安全管理的重要手段. 开启审计,虽然不同级别的审计会有不同,但是对数据库的性能是有影响的,并且占用存储空间. --1.创建审计数据专用表空间 crea ...
- ALTER FUNCTION - 修改一个函数的定义
SYNOPSIS ALTER FUNCTION name ( [ type [, ...] ] ) RENAME TO newname DESCRIPTION 描述 ALTER FUNCTION 修改 ...
- vue组件之this指向问题
[问题描述] 返回顶部组件里,用到数据操作.通过方法里改动this数据,但发现直接使用失效 mounted() { window.onscroll=function(){ ) { this.isAct ...
- IDEA、Eclipse快捷键对比
IDEA.Eclipse快捷键对比 序号 功能 IDEA Eclipse 1 很多功能:导入包,处理异常,强转cast Alt+Enter 2 导入包,自动修正??? Ctrl+Enter 3 ...
- iOS Development Sites
iOS Development Sites 学习iOS开发有一段时间了,虽然还处于迷茫期,但相比以前的小白痴状态,现在还是蛮有改观的.期间接触了一些很好的网站和博客,现在摘录下来,就当建个索引,没 ...