UVA 796 Critical Links(Tarjan求桥)
题目是PDF就没截图了
这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理
代码:
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
const int N=1e6+7;
struct edge
{
int to;
int pre;
};
edge E[N<<1];
int head[N],tot;
int low[N],dfn[N],ins[N],ts,top,st[N];
vector<pii>ans; void init()
{
CLR(head,-1);
tot=0;
CLR(low,0);
CLR(dfn,0);
CLR(ins,0);
ts=top=0;
ans.clear();
}
inline void add(int s,int t)
{
E[tot].to=t;
E[tot].pre=head[s];
head[s]=tot++;
}
void Tarjan(int u,int pre)
{
low[u]=dfn[u]=++ts;
ins[u]=1;
st[top++]=u;
int v;
for (int i=head[u]; ~i; i=E[i].pre)
{
v=E[i].to;
if(v==pre)
continue;
if(!dfn[v])
{
Tarjan(v,u);
low[u]=min<int>(low[u],low[v]);
if(low[v]>dfn[u])
{
pii temp=pii(u,v);
if(temp.first>temp.second)
swap(temp.first,temp.second);
ans.push_back(temp);
}
}
else if(ins[v])
low[u]=min<int>(low[u],dfn[v]);
}
if(low[u]==dfn[u])
{
do
{
v=st[--top];
ins[v]=0;
}while (u!=v);
}
}
int main(void)
{
int n,u,v,k,i;
while (~scanf("%d",&n))
{
init();
for (i=0; i<n; ++i)
{
scanf("%d (%d)",&u,&k);
while (k--)
{
scanf("%d",&v);
add(u,v);
add(v,u);
}
}
for (i=0; i<n; ++i)
{
if(!dfn[i])
Tarjan(i,-1);
}
sort(ans.begin(),ans.end());
int SZ=(int)ans.size();
printf("%d critical links\n",SZ);
for (i=0; i<SZ; ++i)
printf("%d - %d\n",ans[i].first,ans[i].second);
putchar('\n');
}
return 0;
}
UVA 796 Critical Links(Tarjan求桥)的更多相关文章
- UVA 796 - Critical Links (求桥)
Critical Links In a computer network a link L, which interconnects two servers, is considered criti ...
- UVA 796 Critical Links(无向图求桥)
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号 (与这个点相连的点的个数m) 依次是m个点的 输入到文件结束. 桥输出的时候需要排序 知识汇总: 桥: 无向连通 ...
- UVA 796 Critical Links (tarjan算法求割边)
这是在kuangbin的题目里看到的,不得不吐槽一下,题目中居然没给出数据范围,还是我自己猜的-本来是一道挺裸的题,但是我wa了好多次,原因就是这里面有两个坑点,1重边特判,2输出时左边必须比右边小. ...
- UVA 796 Critical Links —— (求割边(桥))
和求割点类似,只要把>=改成>即可.这里想解释一下的是,无向图没有重边,怎么可以使得low[v]=dfn[u]呢?只要它们之间再来一个点即可. 总感觉图论要很仔细地想啊- -一不小心就弄混 ...
- Uva 796 Critical Links (割边+排序)
题目链接: Uva 796 Critical Links 题目描述: 题目中给出一个有可能不连通的无向图,求出这个图的桥,并且把桥按照起点升序输出(还有啊,还有啊,每个桥的起点要比终点靠前啊),这个题 ...
- uva 796 Critical Links(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 796 Critical Links(模板题)(无向图求桥)
<题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...
- UVA 796 - Critical Links 无向图字典序输出桥
题目:传送门 题意:给你一个无向图,你需要找出里面的桥,并把所有桥按字典序输出 这一道题就是用无向图求桥的模板就可以了. 我一直错就是因为我在输入路径的时候少考虑一点 错误代码+原因: 1 #incl ...
- Uva 796 Critical Links 找桥
这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include < ...
随机推荐
- google maps js v3 api教程(1) -- 创建一个地图
原文地址 google maps javascript官方文档:https://developers.google.com/maps/documentation/javascript/ 在创建地图之前 ...
- 信与信封问题(codevs 1222)
题目描述 Description John先生晚上写了n封信,并相应地写了n个信封将信装好,准备寄出.但是,第二天John的儿子Small John将这n封信都拿出了信封.不幸的是,Small Joh ...
- scp 指定端口
scp -P33033 zp.tar root@111.222.123.01:/da1/web/zhaopin.shouhuobao.com #sshd的端口指定的是33033
- mysql php nginx 源码包下载地址
http://mirror.cogentco.com/pub/mysql/MySQL-5.5/ http://mirrors.sohu.com/php/ http://nginx.org/downlo ...
- tomcat The file is absent or does not have execute permission
[root@centos02 bin]# ./startup.sh Cannot find ./catalina.sh The file is absent or does not have exec ...
- transient关键字使用笔记
>>transient的作用及使用方法 一个对象只要实现了Serilizable接口,这个对象就可以被序列化,java的这种序列化模式为开发者提供了很多便利,我们可以不必关系具体序列化的过 ...
- Entity FrameWork 中使用Expression<Func<T,true>>访问数据库性能优化
问题的本质是:扩展的Where方法有四个参数重载.传进去Func<T,true>那么返回值是IEnumable的接口类型的集合,如果是Expression<Func<T,tru ...
- 完美搞定《DOCKER IN ACTION》第二章示例
起来!!!命令如下: 建立第一个web docker docker run --detach --name web nginx:latest 建立第二个web_test docker docker r ...
- poj 2245 水题
求组合数,dfs即可 #include<cstdio> #include<iostream> #include<algorithm> #include<cst ...
- Azure DocumentDB对比MongoDB
(此文章同时发表在本人微信公众号"dotNET每日精华文章") 今天推荐的文章对Azure DocumentDB和MongoDB的进行了比较,也给出了一些使用建议. 我想很多朋友都 ...