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 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
随机推荐
- Android 使用pl.droidsonroids.gif.GifImageView在安卓中显示动图遇到的问题
在做一款聊天软件,其中聊天界面需要发送表情,而表情都是动图,在安卓中想要显示动图,就要借助第三方框架,我选的是pl.droidsonroids.gif.GifImageView. 使用方法如下:你在g ...
- Rxlifecycle使用详解,解决RxJava内存泄露问题
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/1122/3711.html
- 仿微信右滑关闭Activity
SwipeBackLayout 1.AS添加依赖 compile 'me.imid.swipebacklayout.lib:library:1.0.0' eclipse 想办法下载库工程,以库工程形式 ...
- object -c OOP , 源码组织 ,Foundation 框架 详解1
object -c OOP , 源码组织 ,Foundation 框架 详解1 1.1 So what is OOP? OOP is a way of constructing softwar ...
- C语言基础-运算符
sizeof()运算符 •sizeof可以用来计算一个变量或者一个常量.一种数据类型所占的内存字节数 •sizeof一共有3种形式 1.sizeof( 变量\常量 ) sizeof(10 ...
- 把WebForm移植到.Net MVC中
最近写项目,想把以前项目中的几个功能页面移植过来(想偷懒一下),在网上查了很多的资料,多数资料都是直接在MVC中添加WebForm,和我的需求不同.在此非常感谢网友“Jason”给予的帮助,终于搞定了 ...
- pdf 使用模板下载
//根据模板下载模板 /** * * 政策5-8条的创建的pdf的模板 */public String createPdfCashTemplate(PdfCashParam pdfCashParam) ...
- confluence的安装
参考链接:https://www.ilanni.com/?p=11989 一.什么是confluence confluence是一个专业的企业知识管理与协同软件,可以用于构建企业wiki.通过它可以实 ...
- ipv6工具类
package mapreduce.nat; import java.math.BigDecimal; import java.math.BigInteger; import java.net.Ine ...
- Eclipse使用入门指南及技巧
Java是必须的 安装一个JDK就可以了,比如jdk-6u39-windows-x64.exe,安装完毕,会自行安装JRE. 如果不用IDE,这个时候用记事本也是可以写程序,然后用javac编译, ...