题目链接: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. 大数据学习——HDFS的shell

    -help 功能:输出这个命令参数手册 -ls 功能:显示目录信息 示例: hadoop fs -ls hdfs://hadoop-server01:9000/ 备注:这些参数中,所有的hdfs路径都 ...

  2. Linux 磁盘测速

    读: time dd if=/dev/zero of=/test.dbf bs=8k count=1000000 写: time dd if=/dev/zero of=/var/test bs=8k ...

  3. 【转】关于大型网站技术演进的思考(十三)--网站静态化处理—CSI(5)

    讲完了SSI,ESI,下面就要讲讲CSI了 ,CSI是浏览器端的动静整合方案,当我文章发表后有朋友就问我,CSI技术是不是就是通过ajax来加载数据啊,我当时的回答只是说你的理解有点片面,那么到底什么 ...

  4. 【01背包变形】Robberies HDU 2955

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...

  5. 如何通过AS3加载外部SWF文件,调用外部文件文档类的方法?

    一个Flash中通过AS3代码的Loader对象加载另一个SWF文件,并访问其中的文档类中的方法. 简单示例: 主文件:Main.fla, Main.as 被调用的文件:called.swf, Cal ...

  6. Linux 端口开放

    Linux(CentOS): 系统缺省值为32768-61000. 修改方法: 在/etc/sysctl.conf中,增加以下配置:(开放20000-50000为完成端口) net.ipv4.ip_l ...

  7. 50个必备的实用jQuery代码段(转载)

    本文会给你们展示50个jquery代码片段,这些代码能够给你的javascript项目提供帮助.其中的一些代码段是从jQuery1.4.2才开始支持的做法,另一些则是真正有用的函数或方法,他们能够帮助 ...

  8. CodeForces 599A Patrick and Shopping

    水题.每种情况取最小值即可. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...

  9. httpclient失败重连机制

    HttpClient 底层会默认超时自动重发3次,DefaultHttpRequestRetryHandler源码 /**     * Create the request retry handler ...

  10. Go和HTTPS(TLS)

    原文链接: http://studygolang.com/wr?u=http%3a%2f%2ftonybai.com%2f2015%2f04%2f30%2fgo-and-https%2f 近期在构思一 ...