UVA 796 Critical Links

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82833#overview

题目大意:给你一个网络要求这里面的桥。
输入数据:
n 个点
点的编号  (与这个点相连的点的个数m)  依次是m个点的
 
输入到文件结束。
桥输出的时候需要排序
 
知识汇总:
桥:   无向连通图中,如果删除某条边后,图变成不连通了,则该边为桥。
求桥:
在求割点的基础上吗,假如一个边没有重边(重边 1-2, 1->2 有两次,那么 1->2 就是有两条边了,那么 1->2就不算是桥了)。
当且仅当 (u,v) 为父子边,且满足 dfn[u] < low[v]
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <cstring> using namespace std; #define INF 0xfffffff
#define N 11005
#define min(a,b) (a<b?a:b) struct node
{
int x, y; bool friend operator < (node A, node B)
{
if(A.x == B.x)
return A.y < B.y;
return A.x < B.x;
}
}bridge[N]; vector<int> G[N];
int low[N], dfn[N], f[N], Time, n; void init()
{
for(int i = ; i < n; i++)
G[i].clear(); Time = ;
memset(low, , sizeof(low));
memset(dfn, , sizeof(dfn));
memset(f, , sizeof(f));
} void Tarjan(int u, int fa)
{
low[u] = dfn[u] = ++Time;
f[u] = fa;
int len = G[u].size(), v; for(int i = ; i < len; i++)
{
v = G[u][i]; if(!low[v])
{
Tarjan(v, u);
low[u] = min(low[u], low[v]);
}
else if(fa != v)
low[u] = min(low[u], dfn[v]);
}
} void slove()
{
int ans = ; for(int i = ; i < n; i++) //可能不是一个连通图,所以每个点都要遍历
if(!low[i])
Tarjan(i, -);
for(int i = ; i < n; i++)
{
int v = f[i]; if(v != - && dfn[v] < low[i]) // 是桥的条件
{
bridge[ans].x = i;
bridge[ans].y = v;
if(bridge[ans].x > bridge[ans].y)
swap(bridge[ans].x, bridge[ans].y);
ans ++;
}
}
sort(bridge, bridge+ans); printf("%d critical links\n", ans); for(int i = ; i < ans; i++)
printf("%d - %d\n", bridge[i].x, bridge[i].y);
puts("");
} int main()
{
int a, b, m; while(scanf("%d", &n) != EOF)
{
init(); for(int i = ; i < n; i++)
{
scanf("%d (%d)", &a, &m); while(m--)
{
scanf("%d", &b);
G[a].push_back(b);
G[b].push_back(a);
}
}
slove();
}
return ;
}
 

Critical Links的更多相关文章

  1. Light OJ 1026 - Critical Links (图论-双向图tarjan求割边,桥)

    题目大意:双向联通图, 现在求减少任意一边使图的联通性改变,按照起点从小到大列出所有这样的边 解题思路:双向边模版题 tarjan算法 代码如下: #include<bits/stdc++.h& ...

  2. UVA 796 Critical Links(Tarjan求桥)

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

  3. [UVA796]Critical Links(割边, 桥)

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

  4. UVA 796 - Critical Links (求桥)

    Critical Links  In a computer network a link L, which interconnects two servers, is considered criti ...

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

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

  6. Uva 796 Critical Links 找桥

    这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include < ...

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

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

  8. C - Critical Links - uva 796(求桥)

    题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...

  9. UVA 796 Critical Links

    输出桥. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  10. UVA 796 Critical Links (tarjan算法求割边)

    这是在kuangbin的题目里看到的,不得不吐槽一下,题目中居然没给出数据范围,还是我自己猜的-本来是一道挺裸的题,但是我wa了好多次,原因就是这里面有两个坑点,1重边特判,2输出时左边必须比右边小. ...

随机推荐

  1. 配置最漂亮的PyCharm界面,Python程序员必备!

    高逼格超美的IDE界面,是每个程序员的梦想! 随着人工智能/机器学习的兴起,Python作为一门“漂亮的语言”,再次获得广大程序员的关注.而JetBrains出品的PyCharm无疑是最好用的Pyth ...

  2. 【PP系列】SAP 取消报工后修改日期

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[PP系列]SAP 取消报工后修改日期   前言 ...

  3. mooc-IDEA 应用快捷键自动创建测试类--010

    十六.IntelliJ IDEA -应用快捷键自动创建测试类 Step1:在类或接口上,按ctrl+shift+t 选择Create New Test... 则在相应测试包下.创建该测试类. 测试类:

  4. 线程局部存储tls的使用

    线程局部存储(Thread Local Storage,TLS)主要用于在多线程中,存储和维护一些线程相关的数据,存储的数据会被关联到当前线程中去,并不需要锁来维护.. 因此也没有多线程间资源竞争问题 ...

  5. Postman初接触

    https://www.getpostman.com/docs/postman/launching_postman/installation_and_updates

  6. charles模拟弱网情况

    网络主要需要注意什么场景: 弱网功能测试 无网状态测试 网络切换测试 用户体验关注 下面我们使用charles测试弱网,针对不同网络下的测试 打开charles(抓包软件)  

  7. 洛谷P2661 信息传递——并查集

    给一手链接 https://www.luogu.com.cn/problem/P2661 这道题就是 并查集求最小环 TIPS:压缩路径的时候d[x]=d[fa[x]]+d[x],而不是d[x]=d[ ...

  8. ELK日志分析系统之Kibana7.x最新版安装与配置

    3.Kibana的简介 Kibana 让您能够自由地选择如何呈现自己的数据.Kibana 核心产品搭载了一批经典功能:柱状图.线状图.饼图.旭日图等等. 3.1.软件包下载地址:https://www ...

  9. Maven安装、配置环境变量

    一.首先在官网下载安装maven 1.进入官网 2.找到下载位置 3.点进去后是最新版的,若需要最新版就下这个,需要旧版本接着往下滑 4.下载历史版本 (1)点击"archives" ...

  10. Java数组相关算法一

    一.数组反转 1.方法一:创建新数组 int[] arr = {6,29,0,4,3}; int[] arr2 = new int[arr.length]; for (int i = 0; i < ...