https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737

桥:
一个连通图,无向连通图中,如果删除某条边后,图变成不连通了,则该边为桥;
求桥:
在求割点的基础上吗,假如一个边没有重边(重边 1-2, 1->2 有两次,那么 1->2 就是有两条边了,那么 1->2就不算是桥了)。
当且仅当 (u,v) 为父子边,且满足 dfn[u] < low[v]
#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(无向图求桥)的更多相关文章

  1. uva 796 Critical Links(无向图求桥)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. UVA796 - Critical Links(Tarjan求桥)

    In a computer network a link L, which interconnects two servers, is considered critical if there are ...

  3. UVA 796 Critical Links(Tarjan求桥)

    题目是PDF就没截图了 这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理 代码: #include <stdio.h> #include <bits/std ...

  4. uva 796 C - Critical Links(tarjan求桥)

    题目链接:https://vjudge.net/contest/67418#problem/C 题意:求出桥的个数并且按顺序输出 题解:所谓桥就是去掉这条边后连通块增加,套用一下模版就行. #incl ...

  5. UVA 796 Critical Links(无向图求桥)

    题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号  (与这个点相连的点的个数m)  依次是m个点的   输入到文件结束. 桥输出的时候需要排序   知识汇总: 桥:   无向连通 ...

  6. UVA 796 Critical Links(模板题)(无向图求桥)

    <题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...

  7. 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D

    目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...

  8. HDU 4738--Caocao's Bridges(重边无向图求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. (连通图 模板题 无向图求桥)Critical Links -- UVA -- 796

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. AJPFX分析int 和integer的区别

    int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...

  2. android环境搭建环境 cordova run android gradle wrapper报错

    cordova run android命令报错 Error: Could not find an installed version of Gradle either in Android Studi ...

  3. 未找到框架“.NETFramework,Version=v4.5”的引用程序集

    问题描述 一般是在编译的时候会出现这样子的问题, 问题原因: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETF ...

  4. SQL优化基础 使用索引(一个小例子)

    按照本文操作和体会,会对sql优化有个基本最简单的了解,其他深入还需要更多资料和实践的学习: 1. 建表: 复制代码代码如下: create table site_user ( id int IDEN ...

  5. Youtube-dl 简短使用总结

    默认下载bestvideo+bestaudio,并通过ffmpeg -c copy output.mp4 简单的封装进mp4格式,而不进行转码. 有时候bestaudio 是opus编码的,但是mp4 ...

  6. 迅为I.MX6DL开发板飞思卡尔Freescale Cortex A9 迅为-iMX6双核核心板

    核心板参数 尺寸: 51mm*61mm CPU: Freescale Cortex-A9 双核精简版 i.MX6DL,主频 1.2 GHz 内存: 1GB DDR3 存储: 8GB EMMC 存储 E ...

  7. Zend Studio 服务器根目录设置

    在 Apache 服务器根目录里查找 \conf\httpd.conf 例如:C:\AppServ\Apache24\conf\httpd.conf 打开后查找 DocumentRoot 标记 修改调 ...

  8. wpf Command 携带当前窗口

    Command="{Binding GoPayCommand}" CommandParameter="{Binding RelativeSource={RelativeS ...

  9. js小结(一)

    想要的效果:比如说返回 25%  12.5% 33.33% 有几位小数就显示几位,就用 a=Math.round(a*100)/100 如果想要强制返还两位小数,就使用 a=a.toFixed(2); ...

  10. vue-router scrollBehavior的用法

    问题: 使用keep-alive标签后部分安卓机返回缓存页位置不精确问题 解决方案: <div id="app"> <keep-alive> <rou ...