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 ...
随机推荐
- js利用点击事件做一个简单的计算器
先放一个样式图: 源代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- 《Python生物信息学数据管理》中文PDF+英文PDF+代码
生物信息学经典资料,解决生物学问题,通过"编程技法"的形式,涵盖尽可能多的组织.分析.表现结果的策略.在每章结尾都会有为生物研究者设计的编程题目,适合教学和自学.由六部分组成:Py ...
- jumpserver 新建用户收不到邮件
在设置邮件开启pop3/smtp/imap 时 会提示要设置授权码 重启jumpserver 遇到错误 163 邮箱没有收到密码 点击更新没有效果 测试连接成功以后 ,删除用户 ,然后 重新 创建一 ...
- Oracle11g密码忘记处理方法
c:\>sqlplus /nolog sql>connect / as sysdba sql>alter user 用户名 identified by 密码;(注意在这里输入的密码是 ...
- 洛谷 P1176 路径计数2
P1176 路径计数2 题目描述 一个N×N的网格,你一开始在(1, 1),即左上角.每次只能移动到下方相邻的格子或者右方相邻的格子,问到达(N, N),即右下角有多少种方法. 但是这个问题太简单了, ...
- Android——4.2 - 3G移植之路之 AT 通信 (四)
在前文Android--4.2 - 3G移植之路之 reference-ril .pppd 拨号上网 (三)中分析了3G连接网络的流程,当中有说道通过AT指令建立连接, 在这里记录一下3G中的AT通信 ...
- Ubuntu14.04下安装和"激活"Office2010ProPlus与Visio2010(15.11.20Updated)
本人用Ubuntu的时候全然没有打游戏的欲望,故而能够更高效的工作. 尽管说LibreOffice.WPS等等有Ubuntu版本号,可是用着还是没有微软的Office顺手,故而折腾了一下怎样安装Off ...
- atitit.js 与c# java交互html5化的原理与总结.doc
atitit.js 与c# java交互html5化的原理与总结.doc 1. 实现html5化界面的要解决的策略 1 1.1. Js交互 1 1.2. 动态參数个数 1 1.3. 事件监听 2 2. ...
- sql的四大函数
字符串函数: 1.charindex(字符串表达式 1, 字符串表达式2[,整数表达式]) select charindex('ab','BCabTabD')返回 3 select charindex ...
- java读取jpg图片旋转按比例缩放
//入口 public static BufferedImage constructHeatWheelView(int pageWidth, int pageHeight, DoubleHolder ...