UVA 796 Critical Links(Tarjan求割边)
来源:互联网 发布:xquartz2.7.5 mac 编辑:程序博客网 时间:2024/05/17 08:18
套模板。不过用map < int,int > 错了,换成set < pair < int,int > > 结果就对了。
#include <bits/stdc++.h>using namespace std;const int MAXN = 10010;const int MAXM = 100100;struct Edge{ int to,next;};Edge edge[MAXM];int Low[MAXN],DFN[MAXN];int head[MAXN];int tot,Index,cnt;set<pair<int,int>> res;void init(){ memset(head,-1,sizeof(head)); res.clear(); tot = 0;}void addedge(int u, int v){ edge[tot].to = v; edge[tot].next = head[u]; head[u] = tot++;}void Tarjan(int u, int pre){ DFN[u] = Low[u] = ++Index; for(int i = head[u]; i != -1; i = edge[i].next) { int v = edge[i].to; if(!DFN[v]) { Tarjan(v,u); Low[u] = min(Low[u],Low[v]); if(Low[v] > DFN[u]) { ++cnt; res.insert(make_pair(min(u,v),max(u,v))); } } else if(v != pre) Low[u] = min(Low[u],DFN[v]); }}void solve(int n){ memset(Low,0,sizeof(Low)); memset(DFN,0,sizeof(DFN)); Index = cnt = 0; for(int i = 1; i <= n; ++i) if(!DFN[i]) Tarjan(i,i); printf("%d critical links\n",cnt); for(pair<int,int> x : res) printf("%d - %d\n",x.first-1,x.second-1); printf("\n");}int main(){ int n; while(~scanf("%d",&n)) { init(); int u,v,k; for(int i = 0; i < n; ++i) { scanf("%d (%d)",&u,&k); u++; while(k--) { scanf("%d",&v); v++; addedge(u,v); addedge(v,u); } } solve(n); } return 0;}
阅读全文
0 0
- UVA 796 Critical Links(Tarjan求割边)
- UVA 796 Critical Links
- UVA 796 Critical Links
- LightOJ1026-Critical Links-tarjan
- UVA 796 Critical Links(Tarjan求无向图中的桥)
- UVA 796 - Critical Links【求桥】
- UVa 796 Critical Links(无向图求割边)
- UVA 796 Critical Links (桥)
- UVA 796 Critical Links 求桥 .
- UVA 796 Critical Links(求桥)
- LightOJ 1026 - Critical Links (tarjan 找桥)
- UVA 796 - Critical Links (求桥按序输出)
- UVA 796 Critical Links(无向图求桥)
- UVA 796 - Critical Links (求桥,模板题)
- uva 796 Critical Links 割边的数量
- Uva 796 Critical Links 【求桥模板记录】
- LightOJ 1026 Critical Links[求割边]
- UVA 796 Critical Links (求无向图的桥)
- 搜狐2018校招笔试题
- 使用OpenCV训练Haar like+Adaboost分类器的常见问题
- 【NOIP2017提高A组模拟9.14】生命之树 (dsu on tree+trie)
- 1266:寻找幸运数
- tensorflow之session用法简述
- UVA 796 Critical Links(Tarjan求割边)
- 一个简单的51操作系统
- html、css常考的知识点
- 维护篇 17. 固件升级路径表 ❀ 飞塔 (Fortinet) 防火墙
- 全面理解Java内存模型
- HDU 6208 AC自动机 或 暴力?
- vs2008 MFC工程建立
- 使用ppa源方式安装javaJDK
- thinkPHP3.2.3 中伪造表单的一种示例及解决方法