【lightoj-1026】Critical Links(桥)
题意:
给出无向图,求桥的模板题。
#include <bits/stdc++.h>
using namespace std;
const int N = ;
int dfn[N], low[N];//时间戳;low[i]以i为根子树的最小祖先的时间戳
bool vis[N];
vector<int>V[N];
int n, num, c;
pair<int, int>P[N];
void dfs(int s, int f)
{
low[s] = dfn[s] = ++num;
for(unsigned int i = ; i < V[s].size(); i++)
{
int v = V[s][i];
if(!dfn[v])//未访问过(s-v为树边)
{
dfs(v, s);//dfs完更新出low[v]
low[s] = min(low[s], low[v]);
if(low[v] > dfn[s])//割边不加=
P[++c].first = min(v, s), P[c].second = max(v, s);
}
else if(v != f) low[s] = min(low[s], dfn[v]);//回边且不是父子
}
}
int main()
{
int t, n, cas = , m, a, b;
cin>>t;
while(t--)
{
memset(dfn, , sizeof dfn);
memset(low, , sizeof low);
memset(vis, , sizeof vis);
scanf("%d", &n);
for(int i = ; i < n; i++) V[i].clear();
num = , c = ;
for(int i = ; i <= n; i++)
{
scanf("%d (%d)", &a, &m);
while(m--)
{
scanf("%d", &b);
V[a].push_back(b);
V[b].push_back(a);
}
}
for(int i = ; i < n; i++)
{
if(!vis[i])
dfs(i, i);
}
sort(P+, P++c);
printf("Case %d:\n%d critical links\n", ++cas, c);
for(int i = ; i <= c; i++)
printf("%d - %d\n", P[i].first, P[i].second);
}
return ;
}
【lightoj-1026】Critical Links(桥)的更多相关文章
- Light OJ - 1026 - Critical Links(图论-Tarjan算法求无向图的桥数) - 带详细注释
原题链接 无向连通图中,如果删除某边后,图变成不连通,则称该边为桥. 也可以先用Tajan()进行dfs算出所有点 的low和dfn值,并记录dfs过程中每个 点的父节点:然后再把所有点遍历一遍 ...
- Light OJ 1026 - Critical Links (图论-双向图tarjan求割边,桥)
题目大意:双向联通图, 现在求减少任意一边使图的联通性改变,按照起点从小到大列出所有这样的边 解题思路:双向边模版题 tarjan算法 代码如下: #include<bits/stdc++.h& ...
- lightoj 1026 无向图 求桥
题目链接:http://lightoj.com/volume_showproblem.php?problem=1026 #include<cstdio> #include<cstri ...
- UVA 796 Critical Links(Tarjan求桥)
题目是PDF就没截图了 这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理 代码: #include <stdio.h> #include <bits/std ...
- [UVA796]Critical Links(割边, 桥)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 796 - Critical Links (求桥)
Critical Links In a computer network a link L, which interconnects two servers, is considered criti ...
- uva 796 Critical Links(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 796 Critical Links(无向图求桥)
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号 (与这个点相连的点的个数m) 依次是m个点的 输入到文件结束. 桥输出的时候需要排序 知识汇总: 桥: 无向连通 ...
- C - Critical Links - uva 796(求桥)
题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...
随机推荐
- 0601-Zuul构建API Gateway-API gateway简介、基础使用、路由配置、负载配置
一.API Gateway简介 参看:http://www.cnblogs.com/bjlhx/p/8794437.html 二.zuul简介[路由器和过滤器:Zuul] 在微服务架构的组成部分进行路 ...
- 【TensorFlow】tf.nn.conv2d是怎样实现卷积的?
tf.nn.conv2d是TensorFlow里面实现卷积的函数,参考文档对它的介绍并不是很详细,实际上这是搭建卷积神经网络比较核心的一个方法,非常重要 tf.nn.conv2d(input, fil ...
- [Spring ] RequestParam VS PathVariable
仔细一想,感觉没啥需要区分的呢.就是简单明确了两种url定义的背景. PathVariable这种,主要是针对restful类型的url.这种path的定义就要根据restful的规范了. 根据昨天开 ...
- Hive学习路线图--张丹老师
前言 Hive是Hadoop家族中一款数据仓库产品,Hive最大的特点就是提供了类SQL的语法,封装了底层的MapReduce过程,让有SQL基础的业务人员,也可以直接利用Hadoop进行大数据的操作 ...
- Bootstrap实现的页面
实现的效果如图,使用bootstrap需要至少三个文件 去bootstrap网上下载,然后使用这三个文件可以了 使用方式,通过标签,class命名来引用已经定制好的html样式 <!DOCTYP ...
- 【Github教程】史上最全github使用方法:github入门到精通(转自eoeandroid.com)
本文来源:http://www.eoeandroid.com/thread-274556-1-1.html 另附经典教程网址 :http://wuyuans.com/2012/05/github-si ...
- 关于Python字符编码encode和decode
(注:本文部分内容摘自互联网,由于作者水平有限,不足之处,还望留言指正.) 记得几天前,部门的一个小姑娘问我,怎么她Python打印出来的中文信息都乱码了?我走过去,略思一二,瞬间给她搞定,其实这是字 ...
- 微信小程序获取验证码倒计时
getVerificationCode: function() { var that = this; var currentTime = that.data.currentTime; that.set ...
- poj2993
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; stru ...
- centos、linux关机与重启命令详解
Linux centos关机与重启命令详解与实战 Linux centos重启命令: 1.reboot 2.shutdown -r now 立刻重启(root用户使用) 3.shutdown -r 1 ...