Critical Links

Time Limit: 3000ms
Memory Limit: 131072KB

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 program reads sets of data from a text file. Each data set specifies the structure of a network and has the format:

...

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

The result of the program is on standard output. For each data set the program prints the number of critical links and the critical links, one link per line, starting from the beginning of the line, as shown in the sample output below. The links are listed in ascending order according to their first element. The output for the data set is followed by an empty line.

 

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的更多相关文章

  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 ...

随机推荐

  1. navigator.mediaDevices.getUserMedia

    navigator.mediaDevices.getUserMedia: 作用:为用户提供直接连接摄像头.麦克风的硬件设备的接口 语法: navigator.mediaDevices.getUserM ...

  2. 新人 记录VUE中分页实现

    关于函数传值 this.getPurchaseHistoryData(index, num,timeType);第一位是显示的页数,第二是控制首页4上一页-1下一页是2末页是5 第三是是对昨天是1,今 ...

  3. 关于vue自定义事件中,传递参数的一点理解

    例如有如下场景 先熟悉一下Vue事件处理 <!-- 父组件 --> <template> <div> <!--我们想在这个dealName的方法中传递额外参数 ...

  4. 题解 P3243 【[HNOI2015]菜肴制作】

    这道题看起来就是个裸的拓扑排序,抄上模板就能AC. 上面这种想法一看就不现实,然鹅我第一次还真就这么写了,然后被随意hack. 我们需要注意一句话: 现在,酒店希望能求出一个最优的菜肴的制作顺序,使得 ...

  5. CODEVS——T 2833 奇怪的梦境

    http://codevs.cn/problem/2833/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Descr ...

  6. ArcGIS api for javascript——合并两个ArcGIS Online服务

    描述 这个示例创建一个地图并ArcGIS Online增加连个图层到地图.ArcGIS Online是由ESRI体提供的一组切片地图服务,可以用来通过高质量的地图和数据增强应用.这个示例增加影像和运输 ...

  7. 美团实习生电面之谈(成功拿到offer)

    3月底进行了美团的一次实习生面试(Java研发project师).当时顺利的通过一面.以下是我的一面: 1.CPU由哪些部分组成 2.线程和进程的差别 3.Java类载入机制 4.怎样实现一个字符串的 ...

  8. LSTM入门学习——本质上就是比RNN的隐藏层公式稍微复杂了一点点而已

    LSTM入门学习 摘自:http://blog.csdn.net/hjimce/article/details/51234311 下面先给出LSTM的网络结构图: 看到网络结构图好像很复杂的样子,其实 ...

  9. 3.菜鸟教你一步一步开发 web service 之 axis 服务端创建

    转自:https://blog.csdn.net/shfqbluestone/article/details/37610601 第一步,新建一个工程,如图: 选 Java 写一个工程名,选择好工程路径 ...

  10. pigofzhou的巧克力棒

    Description 众所周知,pigofzhou有许多妹子.有一天,pigofzhou得到了一根巧克力棒,他想把这根巧克力棒分给他的妹子们.具体地,这根巧克力棒长为 n,他想将这根巧克力棒折成 n ...