poj 3177 Redundant Paths (双连通)
来源:互联网 发布:做豆浆用什么机器知乎 编辑:程序博客网 时间:2024/05/24 06:13
http://poj.org/problem?id=3177
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.
看ζёСяêτ - 小優YoU 的解析很明白的哦,讲述的太明白了
少在缩点树上增加多少条树边,使得这棵树变为一个双连通图”。
首先知道一条等式:
若要使得任意一棵树,在增加若干条边后,变成一个双连通图,那么
至少增加的边数 =( 这棵树总度数为1的结点数 + 1 )/ 2
http://blog.csdn.net/lyy289065406/article/details/6762370
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <cstdlib>#include <limits>#include <queue>#include <stack>#include <vector>#include <map>using namespace std;#define N 5005#define INF 0xfffffff#define PI acos (-1.0)#define EPS 1e-8vector <vector <int> > G;int n, m, Time, ans, cnt, top;int low[N], dfn[N], ft[N], f[N], eg[N], Stack[N];void Init ();void tarjan (int u, int fa);void solve ();int main (){ while (~scanf ("%d%d", &n, &m)) { int a, b; Init (); while (m--) { scanf ("%d%d", &a, &b); G[a].push_back (b); G[b].push_back (a); } solve (); } return 0;}void Init (){ G.clear (); G.resize (n+1); memset (low, 0, sizeof (low)); memset (dfn, 0, sizeof (dfn)); memset (Stack, 0, sizeof (Stack)); memset (f, 0, sizeof (f)); memset (ft, 0, sizeof (ft)); Time = top = ans = cnt = 0;}void tarjan (int u, int fa){ low[u] = dfn[u] = ++Time; Stack[top++] = u; f[u] = fa; int len = G[u].size (), v, k = 0; for (int i=0; i<len; i++) { v = G[u][i]; if (v == fa && !k)//如果有重边的话,第一条边可以不用走 { k++; continue; } if (!dfn[v]) { tarjan (v, u); low[u] = min (low[u], low[v]); } else low[u] = min (low[u], dfn[v]); } if (low[u] == dfn[u]) { do { v = Stack[--top]; ft[v] = cnt; }while (u != v); cnt++; }}void solve (){ int deg[N] = {0}; for (int i=1; i<=n; i++) if (!low[i]) tarjan (i, i); for (int i=1; i<=n; i++) { int v = f[i]; if (ft[i] != ft[v]) deg[ft[i]]++, deg[ft[v]]++;//计算叶子节点的度 } for (int i=0; i<cnt; i++) if (deg[i] == 1) ans++;//度为1 printf ("%d\n", (ans+1)/2);}
0 0
- POJ 3177 Redundant Paths (双连通)
- poj 3177 Redundant Paths (双连通)
- poj 3177 Redundant Paths 边双连通
- poj 3177 Redundant Paths 边双连通
- poj 3177 Redundant Paths(构造边双连通)
- POJ -- 3177 Redundant Paths(边双连通)
- [POJ 3177]Redundant Paths[边双连通][Tarjan][缩点]
- poj 3177 Redundant Paths 【图论-边双连通】
- POJ 3177 Redundant Paths(边双连通分量)
- POJ-3177 Redundant Paths (边双连通分量[Tarjan])
- poj 3177 Redundant Paths(双连通分量)
- POJ-3177-Redundant Paths【双连通分支】
- POJ 3352 Road Construction POJ 3177 Redundant Paths(边双连通图 Tarjan+缩点)
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连通)
- POJ 3177 Redundant Paths (边双连通,缩点,判重)
- POJ 3177 Redundant Paths(Tarjan Algorithm求边双连通)
- POJ 3177 Redundant Paths 边的双连通分量
- [边双连通分量] poj 3177 Redundant Paths
- 程序员修炼之道系列 - 参与的开源项目和阅读的书籍
- BFS (广度优先搜索)
- Context的getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用
- iOS技术框架构和更新版本的技术特性
- !!使用Caffe对图片进行训练并分类的简单流程
- poj 3177 Redundant Paths (双连通)
- 数据挖掘流程
- 南邮 OJ 1899 树木枝干问题I
- Leetcode_237_Delete Node in a Linked List
- Android 拍照获取源图像
- 性能优化之Java(Android)代码优化
- Java学习笔记四——接口与内部类
- 哈希-4 Values whose Sum is 0
- split 分割 字符串(分隔符如:* ^ : | , .) 及注意点