题目是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求桥)的更多相关文章

  1. UVA 796 - Critical Links (求桥)

    Critical Links  In a computer network a link L, which interconnects two servers, is considered criti ...

  2. UVA 796 Critical Links(无向图求桥)

    题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号  (与这个点相连的点的个数m)  依次是m个点的   输入到文件结束. 桥输出的时候需要排序   知识汇总: 桥:   无向连通 ...

  3. UVA 796 Critical Links (tarjan算法求割边)

    这是在kuangbin的题目里看到的,不得不吐槽一下,题目中居然没给出数据范围,还是我自己猜的-本来是一道挺裸的题,但是我wa了好多次,原因就是这里面有两个坑点,1重边特判,2输出时左边必须比右边小. ...

  4. UVA 796 Critical Links —— (求割边(桥))

    和求割点类似,只要把>=改成>即可.这里想解释一下的是,无向图没有重边,怎么可以使得low[v]=dfn[u]呢?只要它们之间再来一个点即可. 总感觉图论要很仔细地想啊- -一不小心就弄混 ...

  5. Uva 796 Critical Links (割边+排序)

    题目链接: Uva 796 Critical Links 题目描述: 题目中给出一个有可能不连通的无向图,求出这个图的桥,并且把桥按照起点升序输出(还有啊,还有啊,每个桥的起点要比终点靠前啊),这个题 ...

  6. uva 796 Critical Links(无向图求桥)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. UVA 796 Critical Links(模板题)(无向图求桥)

    <题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...

  8. UVA 796 - Critical Links 无向图字典序输出桥

    题目:传送门 题意:给你一个无向图,你需要找出里面的桥,并把所有桥按字典序输出 这一道题就是用无向图求桥的模板就可以了. 我一直错就是因为我在输入路径的时候少考虑一点 错误代码+原因: 1 #incl ...

  9. Uva 796 Critical Links 找桥

    这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include < ...

随机推荐

  1. 【python】any()和all()

    any(iterable) 版本:该函数适用于2.5以上版本,兼容python3版本. 说明:如果iterable的任一元素不为0.''.False,返回True. all(iterable) 说明: ...

  2. python文件取MD5

    import hashlib def md5sum(filename, blocksize=65536): hash = hashlib.md5() with open(filename, " ...

  3. [Android Pro] Android fastboot刷机和获取Root权限

    参考文章: https://developers.google.com/android/nexus/images 转载自:    http://www.inexus.co/article-1280-1 ...

  4. 或许您还不知道的八款Android开源游戏引擎

    很多初学Android游戏开发的朋友,往往会显得有些无所适从,他们常常不知道该从何处入手,每当遇到自己无法解决的难题时,又往往会一边羡慕于iPhone下有诸如Cocos2d-iphone之类的免费游戏 ...

  5. struts2中各种值栈问题

    struts2中OGNL和 ValueStack(一) 收藏 学习的时候,总分不清楚在struts2中页面的传值和取值是怎么来完成的,所以从网上搜了很多资料,现在把这些资料总结写,留着以后参考..看完 ...

  6. Oracle 操作 - 配置

    http://blog.csdn.net/flyingbox/article/details/1823231 http://blog.csdn.net/libingquan008/article/de ...

  7. Linux查询网址

    1.man查询手册 LINUX MAN PAGES ONLINE: http://man.he.net/ 2.编码规范 https://www.kernel.org/doc/Documentation ...

  8. jQuery Mobile 基础(第二章)

    1.可折叠块: <div data-role="collapsible"> <h1>点击我 - 我可以折叠!</h1> <p>我是可 ...

  9. linux tricks 之 BUILD_BUG_ON_ZERO.

    ------------------------------------------- 本文系作者原创, 欢迎大家转载! 转载请注明出处:netwalker.blog.chinaunix.net -- ...

  10. 深入理解 KVC\KVO 实现机制 — KVC

    KVC和KVO都属于键值编程而且底层实现机制都是isa-swizzing,所以本来想放在一起讲的.但是篇幅有限所以就分成了两篇博文 KVO实现机制传送门 KVC概述 KVC是Key Value Cod ...