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

  1. 8
  2. 0 (1) 1
  3. 1 (3) 2 0 3
  4. 2 (2) 1 3
  5. 3 (3) 1 2 4
  6. 4 (1) 3
  7. 7 (1) 6
  8. 6 (1) 7
  9. 5 (0)
  10.  
  11. 0

Sample Output

  1. 3 critical links
  2. 0 - 1
  3. 3 - 4
  4. 6 - 7
  5.  
  6. 0 critical links

Source

 
解题:求割边
 
  1. #include <bits/stdc++.h>
  2. #define pii pair<int,int>
  3. using namespace std;
  4. const int maxn = ;
  5. struct arc{
  6. int u,v,next;
  7. arc(int x = ,int y = ,int z = -){
  8. u = x;
  9. v = y;
  10. next = z;
  11. }
  12. }e[];
  13. int head[maxn],dfn[maxn],low[maxn];
  14. int tot,idx,n,m;
  15. vector< pii >ans;
  16. void add(int u,int v){
  17. e[tot] = arc(u,v,head[u]);
  18. head[u] = tot++;
  19. }
  20. void tarjan(int u,int fa){
  21. dfn[u] = low[u] = ++idx;
  22. bool flag = true;
  23. for(int i = head[u]; ~i; i = e[i].next){
  24. if(e[i].v == fa && flag){
  25. flag = false;
  26. continue;
  27. }
  28. if(!dfn[e[i].v]){
  29. tarjan(e[i].v,u);
  30. low[u] = min(low[u],low[e[i].v]);
  31. 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)));
  32. }else low[u] = min(low[u],dfn[e[i].v]);
  33. }
  34. }
  35. int main(){
  36. int u,v;
  37. while(~scanf("%d",&n)){
  38. ans.clear();
  39. memset(head,-,sizeof(head));
  40. memset(low,,sizeof(low));
  41. memset(dfn,,sizeof(dfn));
  42. for(int i = tot = ; i < n; ++i){
  43. scanf("%d (%d)",&u,&m);
  44. while(m--){
  45. scanf("%d",&v);
  46. add(u,v);
  47. }
  48. }
  49. for(int i = ; i <= n; ++i)
  50. if(!dfn[i]) tarjan(i,-);
  51. printf("%d critical links\n",ans.size());
  52. sort(ans.begin(),ans.end());
  53. for(int i = ; i < ans.size(); ++i)
  54. printf("%d - %d\n",ans[i].first,ans[i].second);
  55. puts("");
  56. }
  57. return ;
  58. }

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. [洛谷P2245]星际导航

    题目大意:有一张n点m边的带权无向图,和一些问题,每次询问两个点之间的路径的最大边权最小是多少. 解题思路:同NOIP2013货车运输,只是数据增大,大变成小,小变成大了而已.所以具体思路见货车运输. ...

  2. spring data jpa实体类映射配置

    @Entity:用来标志实体类,知名这是一个和数据库表映射的实体类 @Id注解指明这个属性映射为数据库的主键 @GeneratedValue注解默认使用主键生成方式为自增,hibernate会自动生成 ...

  3. Unity Shader (二)Cg语言

    一.Cg基本数据类型 float 32位浮点数 half 16位浮点数 int 32位整型 fixed 12位定点数 bool 布尔数据 simpler* 纹理对象的句柄( the handle to ...

  4. main()函数的形参

    main函数中的第一个参数argc代表的是向main函数传递的参数个数,第二个参数argv数组代表执行的程序名称和执行程序时输入的参数 #include <stdio.h> int mai ...

  5. ZooKeeper 特性

    ZooKeeper 拥有一个层次的命名空间.(like distributed)       注意:ZooKeeper 中不许使用相对路径.   一    ZooKeeper 数据模型         ...

  6. libvirt 部分API 介绍

    感谢朋友支持本博客.欢迎共同探讨交流,因为能力和时间有限,错误之处在所难免,欢迎指正! 假设转载,请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  7. .Net商品管理(注释,百度,提问,对比,总结)

    管理控制器 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sys ...

  8. nyoj--19--擅长排列的小明(dfs)

    擅长排列的小明 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 小明十分聪明,而且十分擅长排列计算.比如给小明一个数字5,他能立刻给出1-5按字典序的全排列,如果你想为难 ...

  9. 之前写的收集的一些c++代码片,算法排序,读文件,写日志,快速求积分等等

    写日志: class LogFile { public: static LogFile &instance(); operator FILE *() const { return m_file ...

  10. 8种提升 ASP.NET Web API 性能的方法