【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(求桥)
题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...
随机推荐
- Leetcode 之 Keys Keyboard
1. 2 Keys Keyboard 先把dp的最小不走都设置为无穷大(Integer.MAX_VALUE),初始化条件:dp[0] = dp[1] = 0,状态转移方程为dp[i] = Math.m ...
- Linux学习笔记(11)linux网络管理与配置之一——配置路由与默认网关,双网卡绑定(5-6)
Linux学习笔记(11)linux网络管理与配置之一——配置路由与默认网关,双网卡绑定(5-6) 大纲目录 0.常用linux基础网络命令 1.配置主机名 2.配置网卡信息与IP地址 3.配置DNS ...
- Pytorch(一)
一.Pytorch介绍 Pytorch 是Torch在Python上的衍生物 和Tensorflow相比: Pytorch建立的神经网络是动态的,而Tensorflow建立的神经网络是静态的 Tens ...
- DateTimeTypeHandler
mysql-timestimp-------model-DateTime(jodatime) public class DataTimeTypeHandler extends BaseTypeHand ...
- xlrd、xlwt操作execl表格
在python中操作execl进行数据读写的时候,可以使用xlrd进行文件的读取,使用xlwt将数据写入execl中. 1.xlrd xlwt用来读取execl中的数据,常见的用法如下. (1)打开e ...
- 自动化测试调查问卷送《QTP自动化测试最佳实践》
自动化测试调查问卷送<QTP自动化测试最佳实践> http://automationqa.com/forum.php?mod=viewthread&tid=2308&fro ...
- gvim中对变量的识别
最近在项目中使用gvim打开一个文件,发现对某个变量不识别. 后来发现是gvim中对{$comm_ver},带花括号的变量不识别. 类似这样:parameter memory_spec = " ...
- MapReduce:汇总学生表和成绩表为----学生成绩表
已知两张数据表,其中表一存储的是学生编号.学生姓名:表二存储的是学生编号.考试科目.考试成绩:编写mapreduce程序,汇总两张表数据为一张统一表格. 表一: A001 zhangsan A002 ...
- codeforces 738
D: 题意:一行1*n的格子放船只,船数为a,船的长度为b,每格为0或1,1表示该格并不是船只的一部分,找出最少的格子数使得射击这些格子至少能打中一艘船. 思路:船的长度为b,即每段连续的长度为b的0 ...
- git常用的语句
下面总结出开发中常用的指令: 1.git init:初始化git仓库 2.git add 文件名:把文件添加到暂存区中 3.git commit -m "提交信息":提交暂存区内容 ...