这个题很简单,但是输入有毒,用字符串的我一直RE

然后换成这样瞬间AC

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <stack>
using namespace std;
typedef long long LL;
const int N = 1e4+;
int head[N],tot,n,cnt;
struct Edge{
int u,v,next;
bool operator<(const Edge& rhs)const{
if(u!=rhs.u)return u<rhs.u;
return v<rhs.v;
}
}edge[N*],o[N*];
void add(int u,int v){
edge[tot].v=v;
edge[tot].next=head[u];
head[u]=tot++;
}
int dfn[N],low[N],clk;
void targin(int u,int f){
dfn[u]=low[u]=++clk;
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].v;
if(v==f)continue;
if(!dfn[v]){
targin(v,u);
low[u]=min(low[u],low[v]);
if(dfn[u]<low[v]){
++cnt;
o[cnt].u=min(u,v);
o[cnt].v=max(u,v);
}
}
else if(dfn[v]<low[u])low[u]=dfn[v];
}
}
int main(){
while(~scanf("%d",&n)){
memset(head,-,sizeof(head));
cnt=clk=tot=;
for(int i=;i<=n;++i){
int u,k;
scanf("%d (%d)",&u,&k);
while(k--){int v;scanf("%d",&v);add(u,v);}
}
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
for(int i=;i<n;++i)
if(!dfn[i])targin(i,-);
printf("%d critical links\n",cnt);
if(cnt)sort(o+,o++cnt);
for(int i=;i<=cnt;++i){
printf("%d - %d\n",o[i].u,o[i].v);
}
printf("\n");
}
return ;
}

Uva 796 Critical Links 找桥的更多相关文章

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

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

  2. UVA 796 - Critical Links (求桥)

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

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

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

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

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

  5. UVA 796 Critical Links(Tarjan求桥)

    题目是PDF就没截图了 这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理 代码: #include <stdio.h> #include <bits/std ...

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

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

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

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

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

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

  9. UVA 796 Critical Links

    输出桥. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

随机推荐

  1. 预告:准备开个坑,集中学习一下esp32模块

    对这个模块有兴趣的可以关注我以后的更新,寒假会抽空写几篇心得.

  2. nodejs phantom add click event

    page.evaluate( function() { // find element to send click to var element = document.querySelector( ' ...

  3. WCF入门教程一[什么是WCF]--转载只为学习收藏

    一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...

  4. git/ TortoiseGit 在bitbucket.org 使用证书登陆

    背景:使用https协议在bitbucket中进行pull,push 时每次都要输入密码,比较麻烦还耽误时间,在网上找了下保存密码的方式 使用在用户环境变量中配置_netrc 文件的方式(http:/ ...

  5. dictionary 和 hashtable 区别

    区别:1,Dictionary支持泛型,而Hashtable不支持. 2,Dictionary没有装填因子(Load Facto)概念,当容量不够时才扩容(扩容跟Hashtable一样,也是两倍于当前 ...

  6. spoj 42

    简单题   水水~~ /************************************************************************* > Author: x ...

  7. python常用web框架性能测试(django,flask,bottle,tornado)

    测了一下django.flask.bottle.tornado 框架本身最简单的性能.对django的性能完全无语了. django.flask.bottle 均使用gunicorn+gevent启动 ...

  8. Grok debugger

    http://www.cnblogs.com/vovlie/p/4227027.html http://it.taocms.org/10/5802.htm

  9. java,<E>什么意思?

    泛型 就是指任意类型 比如 HashMap<K,V> 你用的时候 你可以将K,V 设置成任意类 HashMap<String,Integer> K,V 和那个E 一样 Hash ...

  10. ANDROID_MARS学习笔记_S01_011ProgressBar

    文档是这样来设置样式 <ProgressBar android:layout_width="wrap_content" android:layout_height=" ...