题目链接:https://vjudge.net/problem/UVA-796

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: no of servers server0 (no of direct connections) connected server . . . connected server . . . serverno of servers (no of direct connections) connected server . . . connected server The first line contains a positive integer no of servers(possibly 0) which is the number of network servers. The next no of servers lines, one for each server in the network, are randomly ordered and show the way servers are connected. The line corresponding to serverk, 0 ≤ k ≤ no of servers − 1, 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 no of servers − 1.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

题解:

题目要求:按字典序输出桥。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e3+; struct Edge
{
int to, next;
bool cut;
}edge[MAXN*MAXN*];
int tot, head[MAXN]; int Index, DFN[MAXN], Low[MAXN];
int bridge; void addedge(int u, int v)
{
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].cut = false;
head[u] = tot++;
} void Tarjan(int u, int pre)
{
DFN[u] = Low[u] = ++Index;
for(int i = head[u]; i!=-; i = edge[i].next)
{
int v = edge[i].to;
if(v==pre) continue;
if(!DFN[v])
{
Tarjan(v, u);
Low[u] = min(Low[u], Low[v]);
if( Low[v]>DFN[u])
{
edge[i].cut = edge[i^].cut = true;
bridge++;
}
}
else
Low[u] = min(Low[u], DFN[v]);
}
} void init()
{
bridge = tot = ;
memset(head, -, sizeof(head)); Index = ;
memset(DFN, , sizeof(DFN));
memset(Low, , sizeof(Low));
} int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
init();
int u, m, v;
for(int i = ; i<=n; i++)
{
scanf("%d (%d)", &u, &m);
for(int j = ; j<=m; j++)
{
scanf("%d", &v);
addedge(u, v);
addedge(v, u);
}
} for(int i = ; i<n; i++)
if(!DFN[i])
Tarjan(i, i); vector<pair<int, int> >a;
for(int u = ; u<n; u++)
for(int i = head[u]; i!=-; i = edge[i].next)
{
if(edge[i].cut && u<edge[i].to)
a.push_back(make_pair(u, edge[i].to));
} sort(a.begin(), a.end());
printf("%d critical links\n", bridge);
for(int i = ; i<a.size(); i++)
printf("%d - %d\n", a[i].first, a[i].second);
printf("\n");
}
}

UVA796 Critical Links —— 割边(桥)的更多相关文章

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

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

  2. uva-796.critical links(连通图的桥)

    本题大意:求出一个无向图的桥的个数并且按照顺序输出所有桥. 本题思路:注意判重就行了,就是一个桥的裸题. 判重思路目前知道的有两种,第一种是哈希判重,第二种和邻接矩阵的优化一样,就是只存图的上半角或者 ...

  3. UVA796 Critical Links(求桥) 题解

    题意:求桥 思路:求桥的条件是:(u,v)是父子边时 low[v]>dfn[u] 所以我们要解决的问题是怎么判断u,v是父子边(也叫树枝边).我们在进行dfs的时候,要加入一个fa表示当前进行搜 ...

  4. UVA796 - Critical Links(Tarjan求桥)

    In a computer network a link L, which interconnects two servers, is considered critical if there are ...

  5. Uva 796 Critical Links (割边+排序)

    题目链接: Uva 796 Critical Links 题目描述: 题目中给出一个有可能不连通的无向图,求出这个图的桥,并且把桥按照起点升序输出(还有啊,还有啊,每个桥的起点要比终点靠前啊),这个题 ...

  6. Uva 796 Critical Links 找桥

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

  7. Uva796 Critical Links

    用tarjan缩点 然后用dfn[u] < low[v]缩点并且保存起来 在sort一遍输出 #include<stdio.h> #include<string.h> # ...

  8. UVA796:Critical Links(输出桥)

    Critical Links 题目链接:https://vjudge.net/problem/UVA-796 Description: In a computer network a link L, ...

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

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

随机推荐

  1. Java学习之理解多态

    Java 多态 多态是同一个行为具有多个不同表现形式或形态的能力.多态就是同一个接口,使用不同的实例而执行不同操作,多态性是对象多种表现形式的体现.例如:可以把人分为男人和女人,男人有做力气活的能力, ...

  2. 软件测试人员遇到发现的bug不能重现怎么办?

    软件测试人员遇到发现的bug不能重现怎么办?   刚刚进入测试的童鞋们,想必都遇到过提出的bug,开发要求重现之后,但是在系统上已经重现不了的情况吧. 那么碰到这样的情况,不管开发还是测试都很纠结,开 ...

  3. SQL server将某个字符串将按指定字符分解成子字符串(行转列)

    今天突然需要用到这样的方法,在网上找过很多,大体都写的很复杂,这个简单实用.转载自ChineseMoonGod的博客:https://www.cnblogs.com/ChineseMoonGod/p/ ...

  4. python017 Python3 模块

    Python3 模块在前面的几个章节中我们脚本上是用 python 解释器来编程,如果你从 Python 解释器退出再进入,那么你定义的所有的方法和变量就都消失了.为此 Python 提供了一个办法, ...

  5. E-R图

    百度百科:E-R图 100多个数据库,一万多张表,能否使用一张E-R图来表示呢?它是可以的.数据设计依赖于企业的数据,而不是数据库的设计,对企业数据适当做归类,会直接导致数据设计,最终画出E-R图,数 ...

  6. C. The Smallest String Concatenation-C++sort排序~~

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

  7. COJ 1208 矩阵快速幂DP

    题目大意: f(i) 是一个斐波那契数列 , 求sum(f(i)^k)的总和 由于n极大,所以考虑矩阵快速幂加速 我们要求解最后的sum[n] 首先我们需要思考 sum[n] = sum[n-1] + ...

  8. js编程习惯

    1. JS代码中,相同的代码使用成员变量定义. 2. JS中对空值的判断,如if(str == null || str == undefined || str == ‘’){  XXX  } 可以直接 ...

  9. Codeforces Round #292 (Div. 2) D. Drazil and Tiles [拓扑排序 dfs]

    传送门 D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes Drazil cre ...

  10. Flex嵌入HTML页面

    这段时间一直在苦心研究Flex,今天突然想,我们平时都是把swf放到网页中,怎么才能把网页嵌入到Flex中呢?我查了一些资料,然后经过自己的不懈努力,终于搞定. 为了方便,写了个嵌入HTML页面的代理 ...