UVA796 Critical Links (tanjar求桥)
来源:互联网 发布:矩阵的秩8个性质及证明 编辑:程序博客网 时间:2024/06/01 19:09
题目大意:给出一张无向图,按顺序输出桥
注意桥输出的时候需要排序
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>using namespace std;#define LL long long#define mem(a,b) memset(a,b,sizeof a)const int INF = 0x3f3f3f3f;#define MAXN 100100#define MAXM 1000100struct node{ int u,v,flag,next;} edge[MAXM];struct node2{ int u,v;} ans[MAXM];int dfn[MAXN],low[MAXN],s[MAXN],fl[MAXM];int cnt,tot,ant;bool cmp(node2 a,node2 b){ if(a.u!=b.u) return a.u<b.u; return a.v<b.v;}void init(){ mem(s,-1); mem(fl,0); mem(dfn,0); mem(low,0); cnt=tot=ant=0;}void add(int u,int v){ for(int i=s[u]; ~i; i=edge[i].next) { if(edge[i].v==v) { edge[i].flag++; return; } } edge[cnt].u=u; edge[cnt].v=v; edge[cnt].flag=0; edge[cnt].next=s[u]; s[u]=cnt++;}void tarjan(int x,int f){ dfn[x]=low[x]=++tot; for(int i=s[x]; ~i; i=edge[i].next) { int v=edge[i].v; if(v==f) continue; if(!dfn[v]) { tarjan(v,x); low[x]=min(low[x],low[v]); } else { low[x]=min(low[x],dfn[v]); } if(low[v]>dfn[x]&&edge[i].flag==0) { ans[ant].u=x; ans[ant].v=v; if(x>v) swap(ans[ant].u,ans[ant].v); ant++; } }}int main(){ int n,m,u,v; char c; while(~scanf("%d",&n)) { init(); for(int i=0; i<n; i++) { scanf("%d (%d)",&u,&m); for(int i=0; i<m; i++) { scanf("%d",&v); add(u,v); } } for(int i=0; i<n; i++) if(!dfn[i]) tarjan(i,-1); sort(ans,ans+ant,cmp); printf("%d critical links\n",ant); for(int i=0; i<ant; i++) printf("%d - %d\n",ans[i].u,ans[i].v); printf("\n"); } return 0;}
阅读全文
0 0
- UVA796 Critical Links (tanjar求桥)
- uva796 Critical Links(求桥并按边输出)
- UVA796-Critical Links
- UVA796- Critical Links(无向图的桥)
- UVA796.Critical Links——无向图的桥
- Light OJ 1026 Critical Links 求桥
- UVA 796 - Critical Links【求桥】
- UVA 796 Critical Links 求桥 .
- UVA 796 Critical Links(求桥)
- LightOJ 1026 Critical Links 求桥
- UVA796(求桥)
- 796 Critical Links( 求无向图中的桥--模板)
- UVA 796 - Critical Links (求桥按序输出)
- UVA 796 - Critical Links (求桥,模板题)
- Uva 796 Critical Links 【求桥模板记录】
- LightOJ - 1026 Critical Links(桥)
- UVA 796 Critical Links (求无向图的桥)
- UVA 796 Critical Links(Tarjan求无向图中的桥)
- 单链表反转的递归与非递归解法
- 关于js new Date() 出现NaN 的分析
- Android UI 自动化测试之UiDevice
- 使用自定义端口连接SQL Server 2008的方法
- 【jzoj5237】【GDOI2018模拟8.7】【最长公共子序列 】【动态规划】
- UVA796 Critical Links (tanjar求桥)
- 简单使用百度语音合成、工具类直接使用
- LintCode49
- 进程通信值pipe管道
- CodeForces
- Leetcode Median of Two Sorted Arrays
- Appium官网Introduction
- hdu3507Print Article(斜率)
- JZOJ 5234. 【NOIP2017模拟8.7A组】外星人的路径