【Lightoj 1026 B Critical Links】& 桥
来源:互联网 发布:沈阳seo 编辑:程序博客网 时间:2024/06/07 15:41
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 red: 0 - 1, 3 - 4 and 6 - 7 in figure 2.
Figure 1: Original Graph
Figure 2: The Critical Links
It is known that:
- The connection links are bi-directional.
- A server is not directly connected to itself.
- Two servers are interconnected if they are directly connected or if they are interconnected with the same server.
- The network can have stand-alone sub-networks.
Write a program that finds all critical links of a given computer network.
Input
Input starts with an integer T (≤ 15), denoting the number of test cases.
Each case starts with a blank line. The next line will contain n (0 ≤ n ≤ 10000) denoting the number of nodes. Each of the next n lines will contain some integers in the following format:
u (k) v1 v2 … vk
Where u is the node identifier, k is the number of adjacent nodes; v1, v2 … vk are the adjacent nodes of u. You can assume that there are at most 100000 edges in total in a case. Dataset is huge, so use faster i/o methods.
Output
For each case, print the case number first. Then you should print 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 and then second element. Since the graph is bidirectional, print a link u v if u < v.
Sample Input
3
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
2
0 (1) 1
1 (1) 0
Sample Output
Case 1:
3 critical links
0 - 1
3 - 4
6 - 7
Case 2:
0 critical links
Case 3:
1 critical links
0 - 1
Hint
Dataset is huge, use faster I/O methods.
题意 : 找“桥”的个数,桥:关键路径,去掉该边将导致原本相连的点不在联通
思路 : 据说是个模板题(QAQ)
AC代码:
#include<cstdio>#include<cmath>#include<deque>#include<queue>#include<vector>#include<cstring>#include<algorithm>using namespace std;const int MAX = 1e5 + 10;const int INF = 1e9 + 7;typedef long long LL;int nl,head[MAX * 4],n;int ans,d[MAX],lo[MAX],pl;struct node{ int to,next;}st[MAX * 4];struct nod{ int u,v;}sum[MAX * 4];void add(int x,int y){ st[nl] = node{y,head[x]}; head[x] = nl++;}void init(){ ans = nl = 0; pl = 1; memset(head,-1,sizeof head); memset(d,0,sizeof d); memset(lo,0,sizeof lo);}void tr(int x,int from){ d[x] = lo[x] = pl++; for(int i = head[x]; i != -1; i = st[i].next){ int to = st[i].to; if(!d[to]){ tr(to,x); lo[x] = min(lo[x],lo[to]); if(d[x] < lo[to]){ sum[ans] = nod{x,to}; if(x > to) swap(sum[ans].u,sum[ans].v); ans++; } } else if(to != from) lo[x] = min(lo[x],d[to]); }}void solve(){ for(int i = 0; i < n; i++) if(!d[i]) tr(i,-1);}int T,x,m,a,cas = 0;bool cmp(nod i,nod j){ if(i.u == j.u) return i.v < j.v; return i.u < j.u;}void output(){ if(ans) sort(sum,sum + ans,cmp); printf("Case %d:\n",++cas); printf("%d critical links\n",ans); for(int i = 0; i < ans; i++) printf("%d - %d\n",sum[i].u,sum[i].v);}int main(){ scanf("%d",&T); while(T--){ init(); scanf("%d",&n); for(int i = 0; i < n; i++){ scanf("%d (%d)",&x,&m); while(m--){ scanf("%d",&a); add(x,a); } } solve(); output(); } return 0;}
- 【Lightoj 1026 B Critical Links】& 桥
- LightOJ - 1026 Critical Links(桥)
- LightOJ 1026 - Critical Links (tarjan 找桥)
- LightOJ 1026 Critical Links 求桥
- LightOJ 1026 Critical Links[求割边]
- lightoj 1026 - Critical Links 【DFS求块 + 边双连通求桥】
- Light OJ 1026 Critical Links 求桥
- UVA 796 - Critical Links【求桥】
- Critical Links(连通图 桥)
- UVA 796 Critical Links (桥)
- UVA 796 Critical Links 求桥 .
- UVA 796 Critical Links(求桥)
- UVA796 Critical Links (tanjar求桥)
- UVA 796 Critical Links
- UVA 796 Critical Links
- LightOJ1026-Critical Links-tarjan
- UVA796-Critical Links
- Light 1026 - Critical Links (边-双连通分量 + 缩点)
- iOS 关于Safari浏览器和Chrome浏览器Video标签的区别
- fiddler 的教程
- java Calendar Date 获取传入日期所在月或年的第一天和最后一天
- 阿里云Tech Insight 企业迁云实战专场强势来袭!
- Delphi第三方控件dxdbgrid显示小数时不显示小数点前的0的解决办法
- 【Lightoj 1026 B Critical Links】& 桥
- a是
- java读取文件内容方法总结大全(观止)(待续)
- php的进程管理
- 【云栖大会】刚刚成立的达摩院 是马云眼中阿里巴巴留给世界最好的东西之一
- 苹果正在与 LG Display 合作,打造可折叠 iPhone
- lnmp环境搭建之mysql篇
- Lombok介绍及使用方法 lombok简介
- 利用de Casteljau算法绘制Bezier曲面