kuangbin专题 专题九 连通图 Critical Links UVA - 796
题目链接:https://vjudge.net/problem/UVA-796
题目:裸的求桥,按第一个元素升序输出即可。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define pb push_back
#define fi first
#define se second const int N = (int)1e3+;
int n,tot,tim;
int head[N],dfn[N],low[N];
struct node{
int to;
int nxt;
}e[N*N];
vector<pair<int,int> > cut; void init(){
for(int i = ; i <= n; ++i){
head[i] = -;
dfn[i] = ;
}
tim = tot = ;
} inline void add(int u,int v){
e[tot].to = v;
e[tot].nxt = head[u];
head[u] = tot++;
} void tarjan(int now,int pre){
dfn[now] = low[now] = ++tim;
int to;
for(int o = head[now]; ~o; o = e[o].nxt){
to = e[o].to;
if(to == pre) continue;//双向边的判断
if(!dfn[to]){
tarjan(to,now);
low[now] = min(low[now],low[to]);
//桥的条件
if(dfn[now] < low[to]) cut.pb(make_pair(min(now,to),max(now,to)));
}
else if(low[now] > dfn[to]) low[now] = dfn[to];
}
} void _ans(){ int ans = cut.size();
sort(cut.begin(),cut.end());
printf("%d critical links\n",ans);
for(int i = ; i < ans; ++i) printf("%d - %d\n",cut[i].fi,cut[i].se);
printf("\n");
cut.clear();
} int main(){ int u,v,m;
while(~scanf("%d",&n)){
init(); for(int i = ; i < n; ++i){
scanf("%d (%d)",&u,&m);
for(int j = ; j < m; ++j){
scanf("%d",&v);
add(u,v);
}
} for(int i = ; i < n; ++i) if(!dfn[i]) tarjan(i,i);
_ans();
} return ;
}
kuangbin专题 专题九 连通图 Critical Links UVA - 796的更多相关文章
- [kuangbin带你飞]专题九 连通图C - Critical Links UVA - 796
这道题就是要求桥的个数. 那么桥相应的也有判定的定理: 在和u相邻的节点中,存在一个节点是最小的时间戳都比 当前u的访问次序要大,也就是说这个点是只能通过果u到达,那么 他们之间相邻的边就是的桥 #i ...
- (连通图 模板题 无向图求桥)Critical Links -- UVA -- 796
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- C - Critical Links - uva 796(求桥)
题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...
- [kuangbin带你飞]专题九 连通图B - Network UVA - 315
判断割点的性质: 如果点y满足 low[y]>=dfn[x] 且不是根节点 或者是根节点,满足上述式子的有两个及其以上. 就是割点 如果是起点,那么至少需要两个子节点满足上述条件,因为它是根节点 ...
- [kuangbin带你飞]专题九 连通图
ID Origin Title 76 / 163 Problem A POJ 1236 Network of Schools 59 / 177 Problem B UVA 315 Ne ...
- 「kuangbin带你飞」专题十九 矩阵
layout: post title: 「kuangbin带你飞」专题十九 矩阵 author: "luowentaoaa" catalog: true tags: mathjax ...
- 给自己的小练习19-[kuangbin带你飞]专题九连通图
没有写题解.补一波 Network of Schools 问题1:求有向图中入度为0的点个数 问题2:使得整个图变成一个联通分量 问题1直接缩点统计 问题2=max(入度为0的点,出度为0的点),注意 ...
- 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 ...
随机推荐
- 【巨杉数据库SequoiaDB】企业级和开源领域“两开花”,巨杉引领国产数据库创新
2019年12月15日,OSC 源创会·年终盛典在深圳圆满举行.巨杉数据库作为业界领先的金融级分布式数据库厂商, 获得 “2019年开源数据库先锋企业” 及 “2019 GVP-Gitee最有价值开源 ...
- LaTeX技巧006:使用pdfLaTeX时,添加PDF文件属性的方法
PDF文件中含有标题.主题.作者.关键字等属性.这些属性,在Acrobat Reader或者Foxit Reader中可以通过”文件”菜单下的”属性”查看,在Acrobat Read中还可以使用Ctr ...
- 剑指offer 15.链表反转
15.链表反转 题目描述 输入一个链表,反转链表后,输出新链表的表头. PHead,pre, next分别指向当前结点, 前一个结点, 后一个结点,每次迭代先更新当前结点的指针,记录下个结点的指向,转 ...
- c#后端 小程序上传图片
c#后端: /// <summary> /// 上传图片 /// </summary> /// <returns></returns> [HttpPos ...
- JUC之CountDownLatch和CyclicBarrier的区别 (转)
CountDownLatch和CyclicBarrier的功能看起来很相似,不易区分,有一种谜之的神秘.本文将通过通俗的例子并结合代码讲解两者的使用方法和区别. CountDownLatch和Cycl ...
- <软件工程基础>个人项目——数独
参见GitHub:https://github.com/1773262526/Software-Foundation Personal Software Process Stages ...
- JS代码的位置
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- AntDesign(React)学习-13 Warning XX should not be prefixed with namespace XXX
有篇UMI入门简易教程可以看看:https://www.yuque.com/umijs/umi/hello 程序在点击操作时报了一个Warning: [sagaEffects.put] User/up ...
- 高级特征工程I
Mean encodings 以下是Coursera上的How to Win a Data Science Competition: Learn from Top Kagglers课程笔记. 学习目标 ...
- Introduction to SQL
目录 SELECTING SELECTing single columns SELECTing multiple columns select all SELECT DISTINCT Learning ...