这个题很简单,但是输入有毒,用字符串的我一直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. 对.net orm工具Dapper在多数据库方面的优化

    Dapper是近2年异军突起的新ORM工具,它有ado.net般的高性能又有反射映射实体的灵活性,非常适合喜欢原生sql的程序员使用,而且它源码很小,十分轻便.我写本博客的目的不是为了介绍Dapper ...

  2. asp 文件上传(无组件上传)

    文件1.上传界面文件 upload.htm<html><head><meta http-equiv="Content-Language" conten ...

  3. hdu 3682

    将每个格子标记为 x*n*n+y*n+z  每个格子会有一个独特的编号  将它放入vector中  去重  我一开始用 set 超时 #include <cstdio> #include ...

  4. uva 825

    这个......小学生就会的  坑在输入输出了  两个数之间可能不止一个空格....wa了好几遍啊 #include <cstdio> #include <cstring> # ...

  5. Maven的Dependency怎么找?

    用了Maven,所需的JAR包就不能再像往常一样,自己找到并下载下来,用IDE导进去就完事了,Maven用了一个项目依赖(Dependency)的概念,用俗话说,就是我的项目需要用你这个jar包,就称 ...

  6. pdb文件 小结

    .pdb文件,是VS生成的用于调试的符号文件(program database),保存着调试的信息.在VS的工程属性,C/C++,调试信息格式,设置/Zi,那么VS就会在构建项目时创建PDB文件. 在 ...

  7. weblogic集群无法启动,提示java.lang.NumberFormatException

    我有两台weblogic9.2做的集群A,B,A是主服务器,B是受管服务器,后来通过脚本启动weblogic服务,A服务启动异常,经查后台的日志文件发现报错消息如下: WebLogic Server ...

  8. ORACLE 更新关联多张表

    UPDATE T_XMLC_BILL_HEAD_BAK T1 SET (T1.SENDRECEIVEFLAG, T1.SENDRECEIVEOPERATOR, T1.SENDRECEIVEDATE, ...

  9. highcharts 切换

    <!doctype html> <html lang="en"> <head> <script type="text/javas ...

  10. thread dump

    最近在做性能测试,需要对线程堆栈进行分析,在网上收集了一些资料,学习完后,将相关知识整理在一起,输出文章如下. 一.Thread Dump介绍 1.1什么是Thread Dump? Thread Du ...