UVALive 5292 Critical Links
Critical Links
This problem will be judged on UVALive. Original ID: 5292
64-bit integer IO format: %lld Java class name: Main
In a computer network a link L, which interconnects two servers, is considered critical if there are at least two servers A and B such that all network interconnection paths between A and B pass through L. Removing a critical link generates two disjoint sub-networks such that any two servers of a sub-network are interconnected. For example, the network shown in figure 1 has three critical links that are marked bold: 0 -1,3 - 4 and 6 - 7.
Figure 1: Critical links
It is known that:
- 1.
- the connection links are bi-directional;
- 2.
- a server is not directly connected to itself;
- 3.
- two servers are interconnected if they are directly connected or if they are interconnected with the same server;
- 4.
- the network can have stand-alone sub-networks.
Write a program that finds all critical links of a given computer network.
Input


...

The first line contains a positive integer
(possibly 0) which is the number of network servers. The next
lines, one for each server in the network, are randomly ordered and show the way servers are connected. The line corresponding to serverk,
, specifies the number of direct connections of serverk and the servers which are directly connected to serverk. Servers are represented by integers from 0 to
. Input data are correct. The first data set from sample input below corresponds to the network in figure 1, while the second data set specifies an empty network.
Output
Sample Input
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) 0
Sample Output
3 critical links
0 - 1
3 - 4
6 - 7 0 critical links
Source
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int maxn = ;
struct arc{
int u,v,next;
arc(int x = ,int y = ,int z = -){
u = x;
v = y;
next = z;
}
}e[];
int head[maxn],dfn[maxn],low[maxn];
int tot,idx,n,m;
vector< pii >ans;
void add(int u,int v){
e[tot] = arc(u,v,head[u]);
head[u] = tot++;
}
void tarjan(int u,int fa){
dfn[u] = low[u] = ++idx;
bool flag = true;
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].v == fa && flag){
flag = false;
continue;
}
if(!dfn[e[i].v]){
tarjan(e[i].v,u);
low[u] = min(low[u],low[e[i].v]);
if(low[e[i].v] > dfn[u]) ans.push_back(make_pair(min(e[i].v,e[i].u),max(e[i].u,e[i].v)));
}else low[u] = min(low[u],dfn[e[i].v]);
}
}
int main(){
int u,v;
while(~scanf("%d",&n)){
ans.clear();
memset(head,-,sizeof(head));
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
for(int i = tot = ; i < n; ++i){
scanf("%d (%d)",&u,&m);
while(m--){
scanf("%d",&v);
add(u,v);
}
}
for(int i = ; i <= n; ++i)
if(!dfn[i]) tarjan(i,-);
printf("%d critical links\n",ans.size());
sort(ans.begin(),ans.end());
for(int i = ; i < ans.size(); ++i)
printf("%d - %d\n",ans[i].first,ans[i].second);
puts("");
}
return ;
}
UVALive 5292 Critical Links的更多相关文章
- Light OJ 1026 - Critical Links (图论-双向图tarjan求割边,桥)
题目大意:双向联通图, 现在求减少任意一边使图的联通性改变,按照起点从小到大列出所有这样的边 解题思路:双向边模版题 tarjan算法 代码如下: #include<bits/stdc++.h& ...
- 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 找桥
这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include < ...
- UVA 796 Critical Links(无向图求桥)
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号 (与这个点相连的点的个数m) 依次是m个点的 输入到文件结束. 桥输出的时候需要排序 知识汇总: 桥: 无向连通 ...
- C - Critical Links - uva 796(求桥)
题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...
- UVA 796 Critical Links
输出桥. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
随机推荐
- POJ 3630 Phone List(字典树)
题意 题意:t个case(1<=t<=40),给你n个电话号码(电话号码长度<10)(1 ≤ n ≤ 10000),如果有电话号码是另一个电话号码的前缀,则称这个通讯录是不相容的,判 ...
- Visual Studio2008 和2010 执行程序出现的黑框马上消失解决方法
1 在程序最后加 system("PAUSE"); 要注意包括头文件#include"stdlib.h" //system须要调用这个 ...
- [递推+dfs]ZOJ 3436. July Number
题目大意: 将一个数字的相邻两位的差(的绝对值)组成一个新的数字.不断反复.假设最后得到7,就称这个数为July Number,比方9024 – 922 – 70 – 7. 题目要求1e9范围内给定区 ...
- iOS开发 - 数据归档与恢复 NSKeyedArchiver
归档与恢复归档 归档,英文Archiver['ɑrkɪvə],这里指的是将OC的对象存储为一个文件或者网络上的一个数据块. 恢复归档.英文UnArchiver,指的是将一个来自文件或网络的归档数据块恢 ...
- Git的日常处理流程
前提 本地有2个分支,一个是master,还有一个是local master 默认追踪origin/master local 通过git branch -u origin/master来映射 开发的时 ...
- JavaWeb简单介绍
服务器端编程 技术种类 Servlet JSP Struts Spring Hibernate EJB Web Service Web服务器 IIS Apache Tomcat (提供对JSP和Ser ...
- hdoj--2955--Robberies(背包好题)
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Gym - 100625J Jailbreak 最短路+搜索
http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...
- Lambda表达式相当于一个函数
看来你对Lambda完全不懂.Lambda表达式相当于一个函数. 比如model => model.Name相当于string 一个函数(Model的类型 model) { return ...
- Ubuntu16.04安装java(Oracle jre)
一.安装1.从Oracle官网下载jre-8u161-linux-x64.tar.gz安装文件(下载与浏览器位数一样) 2.切换到所需的安装目录.键入: pipci@ubuntu:~$ cd /usr ...