这个题很简单,但是输入有毒,用字符串的我一直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. owa Your request can't be completed right now. Please try again later.

    Your request can't be completed right now. Please try again later.

  2. ios 8和iOS 9 适用的uidatepicker

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n ...

  3. Gnome 插件介绍

    插件:Applications Menuhttps://extensions.gnome.org/extension/6/applications-menu/ TopIconshttps://exte ...

  4. shell复习笔记----查找与替换

    查找文档 以grep 程序查找文本(匹配文本 matching text)相当方便.传统上有三种程序可以用来查找整个文本文件. grep 最早的文本匹配程序.其最简单的方式就是使用固定字符串 $ wh ...

  5. java对象数组

    问题描述:     java 对象数组的使用 问题解决: 数组元素可以是任何类型(只要所有元素具有相同的类型) 数组元素可以是基本数据类型 数组元素也可以是类对象,称这样的数组为对象数组.在这种情况下 ...

  6. 用CSS截断字符串的两种实用方法

    方法一: 复制代码 代码如下: <div style="width:300px; overflow:hidden; text-overflow:ellipsis; white-spac ...

  7. leetcode3 Two Sum III – Data structure design

    Question: Design and implement a TwoSum class. It should support the following operations: add and f ...

  8. hdu 3646

    DP  状态转移方程还是比较容易想到  关键问题是当前要攻击的怪兽的血量 dp[i][j] = max(dp[i-1][j]+第i只鸟不使用double可杀死的怪兽数, dp[i-1][j-1]+第i ...

  9. POJ2349+prim

    最小生成树 /* prim 题意:给定一些点,一些卫星,一个卫星能连接两个点,点和点之间通信有一定的距离限制. 问能使得所有的点联通的最小距离. */ #include<stdio.h> ...

  10. ubuntu下如何设置主机名

    方法如下: 在终端输入 hostname 查看主机名主机名存放在/etc/hostname中 ,sudo gedit /etc/hostname 修改后保存/etc/hosts 还有一份 , sudo ...