[双连通分量] POJ 3177 Redundant Paths
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 13712 | Accepted: 5821 |
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.
Source
#include<stdio.h>
#include<string.h>
struct mp
{
int begin,to,next;
}map[10010];
int frist[10010],num,dfn[10010],low[10010],times,bridgenum,father[10010];
int degree[10010],con[10010],stack[10010],cnt,top,s[10010];
bool count[10010];
void init()
{
memset(father,0,sizeof(father));
memset(count,0,sizeof(count));
memset(con,0,sizeof(con));
memset(degree,0,sizeof(degree));
memset(s,0,sizeof(s));
memset(stack,0,sizeof(stack));
memset(frist,0,sizeof(frist));
memset(dfn,0,sizeof(dfn));
memset(low,0,sizeof(low));
memset(map,0,sizeof(map));
num=times=bridgenum=cnt=top=0;
}
void add(int x,int y)
{
++num;
map[num].begin=x;map[num].to=y;
map[num].next=frist[x];frist[x]=num;
return;
}
void tarjian(int v)
{
int i;bool flag=true;
dfn[v]=low[v]=++times;
stack[top++]=v;
for(i=frist[v];i;i=map[i].next)
{
if(map[i].to==father[v]&&flag)
{
flag=false;
continue;
}
if(!dfn[map[i].to])
{
father[map[i].to]=v;
tarjian(map[i].to);
if(low[map[i].to]<low[v]) low[v]=low[map[i].to];
}
else
if(dfn[map[i].to]<low[v]) low[v]=dfn[map[i].to];
}
if(low[v]==dfn[v])
{
++cnt;
do
{
v=stack[--top];
s[v]=cnt;
}while(dfn[v]!=low[v]);
}
}
int main()
{
int n,m,a,b,i,u,v,k=0,ans=0,j;
init();
scanf("%d%d",&n,&m);
for(i=0;i<m;++i)
{
scanf("%d%d",&a,&b);
add(a,b);add(b,a);
}
tarjian(1);
for(i=1;i<=n;++i)
{
for(j=frist[i];j;j=map[j].next)
{
v=map[j].to;
if(s[i]!=s[v])
{
++degree[s[i]];
++degree[s[v]];
}
}
}
for(i=1;i<=cnt;++i)
if(degree[i]==2)
++ans;
printf("%d\n",(ans+1)/2);
return 0;
}
[双连通分量] POJ 3177 Redundant Paths的更多相关文章
- 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 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- poj 3177 Redundant Paths(边双连通分量+缩点)
链接:http://poj.org/problem?id=3177 题意:有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新建多少条路,使得任 ...
- POJ 3177 Redundant Paths & POJ 3352 Road Construction(双连通分量)
Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numb ...
- POJ 3177 Redundant Paths(边双连通分量)
[题目链接] http://poj.org/problem?id=3177 [题目大意] 给出一张图,问增加几条边,使得整张图构成双连通分量 [题解] 首先我们对图进行双连通分量缩点, 那么问题就转化 ...
- POJ 3177 Redundant Paths (tarjan边双连通分量)
题目连接:http://poj.org/problem?id=3177 题目大意是给定一些牧场,牧场和牧场之间可能存在道路相连,要求从一个牧场到另一个牧场要有至少两条以上不同的路径,且路径的每条pat ...
- POJ 3177 Redundant Paths (桥,边双连通分量,有重边)
题意:给一个无向图,问需要补多少条边才可以让整个图变成[边双连通图],即任意两个点对之间的一条路径全垮掉,这两个点对仍可以通过其他路径而互通. 思路:POJ 3352的升级版,听说这个图会给重边.先看 ...
- 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:65536KB 64bit IO Format:%I64d & %I64u Sub ...
随机推荐
- Chart 绘制,自带动画效果
package com.example.canvasdemo; import android.annotation.SuppressLint; import android.content.Conte ...
- 学习Uml开始
Um的全称是 Unified Modeling Language, 统一建模语言,uml可以帮助我们做软件需求和软件设计的工作, 1.1UML的定义 UML是一种通用的可视化建模语言,是一种标准化的用 ...
- HTML5 webSQL 中查询结果集 result.rows.item 的用法
加入查询回调函数如下: function(tx,result){ var len = result.rows.length; var recordset = result.rows.item; ){ ...
- Java多线程编程——进阶篇二
一.线程的交互 a.线程交互的基础知识 线程交互知识点需要从java.lang.Object的类的三个方法来学习: void notify() 唤醒在此对象监视器上等待的单个 ...
- mysql复制表结构及检查表、存储过程是否存在
mysql命令行复制表结构的方法: 1.只复制表结构到新表 CREATE TABLE 新表 SELECT * FROM 旧表 WHERE 1=2 或者 CREATE TABLE 新表 LIKE 旧表 ...
- 爷爷辈儿的AX
你是否见过第一版的AXAPTA? @FlemmingLR 晒出了他收藏的老光盘. 这就是爷爷辈儿的AX——AXAPTA Version 1.0.
- Prince2和PMP的区别,大多数人都没有搞清楚!
[涨姿势]Prince2和PMP的区别,大多数人都没搞清楚! 项目管理领域有2个流行的知识体系:☑ 一个是美国项目管理协会(PMI)开发的"项目管理知识体系(PMBOK,Project ...
- ASP。net 测验
Login.aspx using System; using System.Collections.Generic; using System.Linq; using System.Web; usin ...
- Animation小问题整理
1.在动画播放中改变层级内容的名字,不会造成动画内容映射的改变. 2.Animator动画剪辑层级没问题,但是不播放 检查是否Mask损坏,FBX文件的Animations选项下面有个Mask.Uni ...
- python之rabbitMQ篇
一.RabbitMQ安装 RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统,它遵循Mozilla Pulic License开源协议. MQ全称为Message Queue,消息队列 ...