uva 796 Critical Links(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <cstring>
#define N 12010
using namespace std; struct st
{
int x, y;
bool friend operator < (st a, st b)
{
if(a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}//结构体优先级
} node[N]; vector<vector<int> >G; int low[N], dfn[N], f[N];
int n, Time, k; void Init()
{
G.clear();
G.resize(n + );
memset(low, , sizeof(low));
memset(dfn, , sizeof(dfn));
memset(f, , sizeof(f));
Time = k = ;
} void Tarjan(int u, int fa)
{
int i, len, v;
low[u] = dfn[u] = ++Time;
f[u] = fa;
len = G[u].size();
for(i = ; i < len ; i++)
{
v = G[u][i];
if(!dfn[v])
{
Tarjan(v, u);
low[u] = min(low[u], low[v]);
}
else if(fa != v)
low[u] = min(low[u], dfn[v]);
}
} void Solve()
{
int i, v;
for(i = ; i < n ; i++)
if(!low[i])
Tarjan(i, -);
for(i = ; i < n ; i++)
{
v = f[i];
if(v > - && dfn[v] < low[i])
{
node[k].x = v;
node[k].y = i;
if(node[k].x > node[k].y)
swap(node[k].x, node[k].y);
k++;
}
}
sort(node, node + k);//sort排序
printf("%d critical links\n", k);
for(i = ; i < k ; i++)
printf("%d - %d\n", node[i].x, node[i].y);
printf("\n");
} int main()
{
int a, b, m, x;
while(~scanf("%d", &n))
{
Init();
x = n;
while(x--)
{
scanf("%d (%d)", &a, &m);
while(m--)
{
scanf("%d", &b);
G[a].push_back(b);
}
}
Solve();
}
return ;
}
uva 796 Critical Links(无向图求桥)的更多相关文章
- UVA 796 Critical Links(无向图求桥)
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号 (与这个点相连的点的个数m) 依次是m个点的 输入到文件结束. 桥输出的时候需要排序 知识汇总: 桥: 无向连通 ...
- UVA 796 - Critical Links (求桥)
Critical Links In a computer network a link L, which interconnects two servers, is considered criti ...
- UVA 796 - Critical Links 无向图字典序输出桥
题目:传送门 题意:给你一个无向图,你需要找出里面的桥,并把所有桥按字典序输出 这一道题就是用无向图求桥的模板就可以了. 我一直错就是因为我在输入路径的时候少考虑一点 错误代码+原因: 1 #incl ...
- UVA 796 Critical Links —— (求割边(桥))
和求割点类似,只要把>=改成>即可.这里想解释一下的是,无向图没有重边,怎么可以使得low[v]=dfn[u]呢?只要它们之间再来一个点即可. 总感觉图论要很仔细地想啊- -一不小心就弄混 ...
- Uva 796 Critical Links (割边+排序)
题目链接: Uva 796 Critical Links 题目描述: 题目中给出一个有可能不连通的无向图,求出这个图的桥,并且把桥按照起点升序输出(还有啊,还有啊,每个桥的起点要比终点靠前啊),这个题 ...
- UVA 796 Critical Links(模板题)(无向图求桥)
<题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...
- UVA 796 Critical Links(Tarjan求桥)
题目是PDF就没截图了 这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理 代码: #include <stdio.h> #include <bits/std ...
- Uva 796 Critical Links 找桥
这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include < ...
- UVA 796 Critical Links (tarjan算法求割边)
这是在kuangbin的题目里看到的,不得不吐槽一下,题目中居然没给出数据范围,还是我自己猜的-本来是一道挺裸的题,但是我wa了好多次,原因就是这里面有两个坑点,1重边特判,2输出时左边必须比右边小. ...
随机推荐
- BZOJ 1923 外星千足虫(高斯消元)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1923 题意:有n个数字,m次测试.每个数字为0或者1.每次测试选出一些数字出来把他们加起 ...
- Internet Explorer for Mac the Easy Way: Run IE 7, IE8, & IE9 Free in a Virtual Machine
From link: http://osxdaily.com/2011/09/04/internet-explorer-for-mac-ie7-ie8-ie-9-free/ If you’re ...
- BZOJ2073: [POI2004]PRZ
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2073 题解:跟风Xs酱! 数据范围这么小,肯定是状压DP.咦?怎么枚举子集?... 跪烂Xs: ...
- fancybox 点击 js脚本判断验证,fancybox的宽度高度设置
当我们在使用fancybox做弹出窗口的时候,可能在弹窗之前就需要判断一些验证条件,例如我这里有个案例,用户必须先得勾选一个 那么怎么做呢?我们用到fancybox的一个onStart方法就可以了 $ ...
- Java [Leetcode 70]Climbing Stairs
题目描述: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either ...
- FFmpeg 维基百科
FFmpeg是一个自由软件,可以运行音频和视频多种格式的录影.转换.流功能[1],包含了libavcodec ─这是一个用于多个项目中音频和视频的解码器库,以及libavformat——一个音频与视频 ...
- 数据库语言(二):SQL语法实例整理
连接表达式: select * from student join takes on student.ID = takes.ID; 通过on后面的谓词作为连接条件,相同的属性可以出现两次,也就是等价于 ...
- TCP/IP详解学习笔记(10)-TCP连接的建立与中止
TCP是一个面向连接的协议,所以在连接双方发送数据之前,都需要首先建立一条连接.这和前面讲到的协议完全不同.前面讲的所有协议都只是发送数据而已,大多数都不关心发送的数据是不是送到,UDP尤其明显,从编 ...
- android学习笔记六
Android中Activity的Intent大全 Api Level 3: (SDK 1.5) android.intent.action.ALL_APPS android.intent.actio ...
- .NET Remoting
.NET Remoting .NET Remoting是微软早期的分布式通信技术,虽然微软后来通过WCF通用基础通信框架整合掉了,但是通过回顾学习Remoting,反过来学习理解WCF也是很有帮助 ...