POJ3177 边双连通分量
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 18580 | Accepted: 7711 |
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
题意:有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走。现已有m条路,求至少要新建多少条路,使得任何两个牧场之间至少有两条独立的路。两条独立的路是指:没有公共边的路,但可以经过同一个中间顶点。
分析:在同一个边双连通分量中看做同一个点,缩点后,新图是一棵树,树的边就是原无向图的桥。
问题转化为:在树中至少添加多少条边能使图变为双连通图。
结论:添加边数=(树中度为1的节点数+1)/2
代码:
#include<cstdio>
#include<cstring>
#include "algorithm"
using namespace std;
const int N = + ;
const int M = + ;
struct P {
int to, nxt;
} e[M * ];
int head[N], low[N], dfn[N], beg[N], du[N], st[M], ins[M];
int cnt, id, top, num; void add(int u, int v) {
e[cnt].to = v;
e[cnt].nxt = head[u];
head[u] = cnt++;
} void tarjan(int u, int fa) {
low[u] = dfn[u] = ++id;
st[++top] = u;
ins[u] = ;
for (int i = head[u]; i != -; i = e[i].nxt) {
int v = e[i].to;
if (i == (fa ^ )) continue;
if (!dfn[v]) tarjan(v, i), low[u] = min(low[u], low[v]);
else if (ins[v]) low[u] = min(low[u], dfn[v]);
}
if (dfn[u] == low[u]) {
int v;
do {
v = st[top--];
ins[v] = ;
beg[v] = num;
} while (u != v);
num++;
}
} void init() {
cnt = id = top = num = ;
memset(head, -, sizeof(head));
memset(low, , sizeof(low));
memset(dfn, , sizeof(dfn));
memset(ins, , sizeof(ins));
memset(du, , sizeof(du));
} int n, m;
int main() {
scanf("%d%d", &n, &m);
init();
for (int i = ; i < m; i++){
int u, v;
scanf("%d%d", &u, &v);
add(u, v), add(v, u);
}
for (int i = ; i <= n; i++) if (!dfn[i]) tarjan(i, -);
for (int i = ; i <= n; i++) {
for (int j = head[i]; j != -; j = e[j].nxt){
int v = e[j].to;
if (beg[i] != beg[v]) du[beg[i]]++;
}
}
int ans = ;
for (int i = ; i < num; i++)
if (du[i] == ) ans++;
printf("%d\n", (ans + ) / );
return ;
}
POJ3177 边双连通分量的更多相关文章
- poj3177边-双连通分量
题意和poj3352一样..唯一区别就是有重边,预先判断一下就好了 #include<map> #include<set> #include<list> #incl ...
- poj3177 && poj3352 边双连通分量缩点
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12676 Accepted: 5368 ...
- POJ3177 Redundant Paths(边双连通分量+缩点)
题目大概是给一个无向连通图,问最少加几条边,使图的任意两点都至少有两条边不重复路径. 如果一个图是边双连通图,即不存在割边,那么任何两个点都满足至少有两条边不重复路径,因为假设有重复边那这条边一定就是 ...
- poj3177(边双连通分量+缩点)
传送门:Redundant Paths 题意:有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新建多少条路,使得任何两个牧场之间至少有两条独立 ...
- POJ3177 Redundant Paths 双连通分量
Redundant Paths Description In order to get from one of the F (1 <= F <= 5,000) grazing fields ...
- poj3352 Road Construction & poj3177 Redundant Paths (边双连通分量)题解
题意:有n个点,m条路,问你最少加几条边,让整个图变成边双连通分量. 思路:缩点后变成一颗树,最少加边 = (度为1的点 + 1)/ 2.3177有重边,如果出现重边,用并查集合并两个端点所在的缩点后 ...
- poj3177 Redundant Paths 边双连通分量
给一个无向图,问至少加入多少条边能够使图变成双连通图(随意两点之间至少有两条不同的路(边不同)). 图中的双连通分量不用管,所以缩点之后建新的无向无环图. 这样,题目问题等效于,把新图中度数为1的点相 ...
- POJ3177 Redundant Paths 图的边双连通分量
题目大意:问一个图至少加多少边能使该图的边双连通分量成为它本身. 图的边双连通分量为极大的不存在割边的子图.图的边双连通分量之间由割边连接.求法如下: 求出图的割边 在每个边双连通分量内Dfs,标记每 ...
- POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 12439 Acce ...
随机推荐
- SQL Server 数据库修改后不允许保存
打开 工具 - > 选项 -> 设计器,确认[阻止保存要求重新创建表的更改]项是否选中,如果选中,取消即可.
- Orchard Core 文档翻译 (五)自动路由 Autoroute (OrchardCore.Autoroute)
Autoroute (OrchardCore.Autoroute) 此模块允许您为内容项指定自定义URL(永久链接 permalink). Autoroute Part 将此部分附加到内容类型以指定内 ...
- March 17 2017 Week 11 Friday
Simplicity is the ultimate sophistication. 简约才是精巧到了极致. Recently I have spent a great number of time ...
- Android开发最佳学习路线图(转)
Android开发总体路线图: 基础学习——JavaSE: 很多朋友一上手就开始学习Android,似乎太着急了一些. Android应用程序开发是以Java语言为基础的,所以没有扎实 ...
- OC property(声明)
@interface Student : NSObject { int _age; int _no; float _height; } // 当编译器遇到@property时,会自动展开成getter ...
- 每天一个linux命令:df 命令
linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 1.命令格式: df [选项] [文件] 2.命 ...
- Android学习笔记_76_Android ProgressBar 进度条
android 进度条的样式 例1:(默认样式(中等圆形))Xml代码 <ProgressBar android:id="@+id/progressBar1" ...
- HDU 1160(两个值的LIS,需dfs输出路径)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/ ...
- 我和我的广告前端代码(四):后台系统中,初尝vue、vue-cli
有一段都在重构之前文章<我和我的广告前端代码(三):一次重来的机会,必要的技术选型>中提到的广告前台展示项目,原有的基于页面的请求,改成了单广告位请求在这个过程中经历了好几次架构变更以及项 ...
- lucene&solr学习——分词器
下图是语汇单元的生成过程: 从一个Reader字符流开始,创建基于Reader的Tokenizer分词器,经过三个TokenFilter生成语汇单元Tokens. 要看分词器的分析效果,只需要看Tok ...