[双连通分量] 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 ...
随机推荐
- 解决Firefox浏览器每次打开都弹出导入向导的问题
每次打开Firefox浏览器都会弹出导入向导这个页面,只有这个页面关闭后,Firefox界面才会打开. 解决办法: C:\Users\{用户名}\AppData\Roaming\Mozilla\Fir ...
- css样式控制鼠标滑过显示
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Asp.Net在多线程环境下的状态存储问题
在应用开发中,我们经常需要设置一些上下文(Context)信息,这些上下文信息一般基于当前的会话(Session),比如当前登录用户的个人信息:或者基于当前方法调用栈,比如在同一个调用中涉及的多个层次 ...
- Linux 2.6内核Makefile浅析
1 概述 Makefile由五个部分组成: Makefile:根目录Makefile,它读取.config文件,并负责创建vmlinux(内核镜像)和modules(模块文件). .config:内核 ...
- 从yum源下载安装包及依赖包
局域网内所有linux都用yum从外网源安装软件有点浪费,尤其遇到下载慢的情况: 所以考虑下载后传到其他机器安装,还可以保证版本一致(创建一个本地仓库更好,这个后面研究了再记录): 首先安装yum工具 ...
- CentOS 7下关于systemd的一些唠叨话二:systemd服务脚本的编写
CentOS 7继承了RHEL 7的新的特性,例如强大的systemd,而systemd的使用也使得以往系统服务的/etc/init.d的启动脚本的方式就此改变,也大幅提高了系统服务的运行效率.但服务 ...
- XML学习笔记(四)-- 修饰XML文档的CSS
标签(空格分隔): 学习笔记 XML为存储结构化数据提供了强大的方法,但是它没有提供关于数据如何显示地信息,(数据的结构与数据表示无关).可以使用CSS来控制XML文档中各元素的呈现方式. CSS语法 ...
- [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序读取相关数据
这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第七篇:为ASP.NET MVC应用程序 ...
- 《BI项目笔记》历年的初烟水分均值变化分析Cube的建立
主要维度: 班组班次检测项质检日期(时间维度)加工客户加工类型收购类型生产线产地烟叶级别 主要指标:慢速测定_平均值快速测定_平均值红外测定_平均值ETL设计 需要抽取的维度表: 序号 表名 说明 备 ...
- mongoDB 数据导出与导入
一.导出 命令格式:在mongodb/bin目录下 mongoexport -h IP --port 端口 -u 用户名 -p 密码 -d 数据库 -c 表名 -f 字段 -q 条件导出 --csv ...