lightoj 1026 无向图 求桥
题目链接:http://lightoj.com/volume_showproblem.php?problem=1026
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int maxn = ;
const int INF = 0x3f3f3f; vector<int> G[maxn];
int pre[maxn],dfs_clock,low[maxn]; struct ANS{
int l,r;
bool operator < (const ANS& a) const{
return l < a.l || (l == a.l && r < a.r); //排序被坑了,WA了好几次啊,没想后面的情况。
}
}ans[maxn];
int cnt;
int n; void tarjan(int u,int fa){
low[u] = pre[u] = dfs_clock++;
for(int i=;i<G[u].size();i++){
int v = G[u][i];
if(v == fa) continue;
if(!pre[v]){
tarjan(v,u);
low[u] = min(low[u],low[v]);
if(low[v] > pre[u]){
ans[cnt].l = min(u,v);
ans[cnt].r = max(u,v);
cnt++;
}
}
else
low[u] = min(low[u],pre[v]);
}
} void init(){
cnt = ;
dfs_clock = ;
memset(pre,,sizeof(pre));
for(int i=;i<n;i++) G[i].clear();
}
int main()
{
freopen("E:\\acm\\input.txt","r",stdin);
int T;
cin>>T;
for(int t=;t<=T;t++){
scanf("%d",&n);
init();
for(int i=;i<n;i++){
int u,m;
scanf("%d (%d)",&u,&m);
for(int j=;j<=m;j++){
int v;
scanf("%d",&v);
G[u].push_back(v);
}
}
for(int i=;i<n;i++){
if(!pre[i]){
tarjan(i,-);
}
}
printf("Case %d:\n",t);
printf("%d critical links\n",cnt);
sort(ans,ans+cnt);
for(int i=;i<cnt;i++){
printf("%d - %d\n",ans[i].l,ans[i].r);
}
}
}
lightoj 1026 无向图 求桥的更多相关文章
- UVA 796 Critical Links(无向图求桥)
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号 (与这个点相连的点的个数m) 依次是m个点的 输入到文件结束. 桥输出的时候需要排序 知识汇总: 桥: 无向连通 ...
- 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D
目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...
- UVA 796 Critical Links(模板题)(无向图求桥)
<题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...
- HDU 4738--Caocao's Bridges(重边无向图求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- uva 796 Critical Links(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Critical Links-UVa796(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- POJ 3694 Network(并查集缩点 + 朴素的LCA + 无向图求桥)题解
题意:给你一个无向图,有q次操作,每次连接两个点,问你每次操作后有几个桥 思路:我们先用tarjan求出所有的桥,同时我们可以用并查集缩点,fa表示缩点后的编号,还要记录每个节点父节点pre.我们知道 ...
- POJ 3694 Network(无向图求桥+重边处理+LCA)
题目大意: 给你一个无向图,然后再给你一个Q代表有Q次询问,每一次加一条边之后还有几座桥.在这里要对重边进行处理. 每次加入一条边之后,在这条搜索树上两个点的公共祖先都上所有点的桥都没了. 这里重边的 ...
- poj 3694 无向图求桥+lca
题意抽象为: 给一个无向图和一些询问 对于每一次询问: 每次询问都会在图上增加一条边 对于每一次询问输出此时图上桥的个数. 桥的定义:删除该边后原图变为多个连通块. 数据规模:点数N(1 ≤ N ≤ ...
随机推荐
- Encapsulation.
Access control is often referred to as implementation hiding. Wrapping data and methods within class ...
- 让ie6/7/8兼容css3的圆角阴影等特殊效果的方法 PIE1.0.0及placeholder在这些IE下生效的方法
PIE地址:http://css3pie.com/ 使用方法1: #login,#AnnouncementBox { border:3px solid #fff; -webkit-border-r ...
- Netbeans IDE配置
- P2P
https://www.ppmoney.com/Withdraw http://www.daibang.com/
- xcode7 icon图标设置
- 关于C#与.NET Framework
前几天,有一个做测试的问我.NET Framework是什么,和C#是什么关系呢. 下面我就来解释一下.NET Framework是什么:.NET Framework是一个框架,是应用程序运行时所需要 ...
- hdoj 1892(二维树状数组)
Problem H Time Limit : 5000/3000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- IPython,让Python显得友好十倍的外套——windows XP/Win7安装详解
前言 学习python,官方版本其实足够了.但是如果追求更好的开发体验,耐得住不厌其烦地折腾.那么我可以负责任的告诉你:IPython是我认为的唯一显著好于原版python的工具. 整理了 ...
- ARM架构下linux设备树加载的方法
引入设备树后bootloader加载DTB方法: 1. 标准方法 将linux kernel放到内存地址为<kernel img addr>的内存中. 将DTB放到地址为<dtb a ...
- js获取屏幕(设备)宽高
平常获取设备的宽高无非就那几 <script language="javascript"> var h = ""; h += " 网页可见 ...