Critical Links-UVa796(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector> using namespace std;
#define N 200 int low[N],dfn[N],n,fa[N],Stack[N];
int Time,top,ans[N];
struct node
{
int x,y;
}a[N];
vector<vector <int> >G; void Inn()
{
G.clear();
G.resize(n+);
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(fa,,sizeof(fa));
memset(ans,,sizeof(ans));
memset(Stack,,sizeof(Stack));
Time=top=;
}
bool cmp(node c,node d)
{
if(c.x!=d.x)
return c.x<d.x;
else
return c.y<d.y;
}
void Tarjin(int u,int f)
{
low[u]=dfn[u]=++Time;
Stack[top++]=u;
fa[u]=f;
int len, v;
len=G[u].size();
for(int i=; i<len; i++)
{
v=G[u][i];
if(!dfn[v])
{
Tarjin(v,u);
low[u]=min(low[u],low[v]);
}
else if(f!=v)
low[u]=min(low[u],dfn[v]);
}
} void slove()
{
int ans=,i;
for(i=; i<n; i++)
{
if(!dfn[i])
Tarjin(i,-);
}
for(i=; i<n; i++)
{
int v=fa[i];
if(v!=- && low[i]>dfn[v])
{
a[ans].x=i;
a[ans].y=v;
int t;
if(a[ans].x>a[ans].y)
{
t=a[ans].x;
a[ans].x=a[ans].y;
a[ans].y=t;
}
ans++;
} }
sort(a,a+ans,cmp);
printf("%d critical links\n",ans);
for(i=; i<ans; i++)
printf("%d - %d\n",a[i].x,a[i].y);
printf("\n");
} int main()
{
int h,m,b,i;
while(scanf("%d",&n)!=EOF)
{
Inn();
for(i=; i<n; i++)
{
scanf("%d (%d)",&h,&m);
while(m--)
{
scanf("%d",&b);
G[h].push_back(b);
G[b].push_back(h);
}
}
slove();
}
return ;
} /*
8
0 (1) 1
1 (3) 2 0 3
2 (2) 1 3
3 (3) 1 2 4
4 (1) 3
7 (1) 6
6 (1) 7
5 (0)
*/
Critical Links-UVa796(无向图求桥)的更多相关文章
- uva 796 Critical Links(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA796 - Critical Links(Tarjan求桥)
In a computer network a link L, which interconnects two servers, is considered critical if there are ...
- UVA 796 Critical Links(Tarjan求桥)
题目是PDF就没截图了 这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理 代码: #include <stdio.h> #include <bits/std ...
- uva 796 C - Critical Links(tarjan求桥)
题目链接:https://vjudge.net/contest/67418#problem/C 题意:求出桥的个数并且按顺序输出 题解:所谓桥就是去掉这条边后连通块增加,套用一下模版就行. #incl ...
- UVA 796 Critical Links(无向图求桥)
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号 (与这个点相连的点的个数m) 依次是m个点的 输入到文件结束. 桥输出的时候需要排序 知识汇总: 桥: 无向连通 ...
- UVA 796 Critical Links(模板题)(无向图求桥)
<题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...
- 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D
目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...
- HDU 4738--Caocao's Bridges(重边无向图求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- (连通图 模板题 无向图求桥)Critical Links -- UVA -- 796
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- pandas 选择某几列
转自:https://blog.csdn.net/aaa_aaa1sdf/article/details/77414387 col_n = ['名称','收盘价','日期'] a = pd.DataF ...
- 契约式设计(DbC)感想(二)
契约式设计6大原则的理解 在<Design by Contract原则与实践>中,作者定义了契约式设计的6大原则: 区分命令和查询: 将基本查询和派生查询区分开: 针对每个派生查询,设定一 ...
- ArrayList源码分析(基于JDK1.8)
public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess ...
- Java多线程编程核心技术---Lock的基本概念和使用
Lock接口: ReentrantLock的基本功能: ReentrantLock的lock和unlock方法进行加锁,解锁.可以起到和synchronized关键字一样的效果: 选择性通知!!!: ...
- linux 11201(11203) ASM RAC 安装
注意:11G的RAC安装,如果升级,则会新建目录在放软件,原来的不删除,所以所需空间比较大. 1.安装系统,把所有的开发包全部安装上 关掉防火墙和SELinux yum -y install comp ...
- laravel的socialite微信登录之用户信息
要想获取完整的用户信息如下 { , "openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M", "nickname" ...
- python 实现代理服务器
# encoding:utf-8 import socket import thread import re def getAddr(d): a = re.search("Host: (.* ...
- VC++线程函数内怎么调用外部函数
VC++线程函数内怎么调用外部函数 1.把外部函数做成静态函数,就可以直接调用了.2.把外部函数所在的对象通过线程函数参数传到线程里面来,这样线程里可以使用此对象及其函数了.
- JavaSE-15 Log4j参数详解
一:日志记录器输出级别,共有5级(从前往后的顺序排列) ①fatel:指出严重的错误事件将会导致应用程序的退出 ②error:指出虽然发生错误事件,但仍然不影响系统的继续运行 ③warn:表明会出现潜 ...
- pep8摘要
https://www.python.org/dev/peps/pep-0008/ #!/usr/bin/python # -*- coding:utf- -*- # @filename: pep_s ...