用tarjan缩点 
然后用dfn[u] < low[v]缩点并且保存起来 
在sort一遍输出

 #include<stdio.h>
#include<string.h>
#include<algorithm> using namespace std; const int maxn = ; struct Node {
int u;
int v;
int next;
};
struct Edge{
int u;
int v;
};
Edge edge[maxn];
Node node[maxn * ];
int head[maxn];
int dfn[maxn];
int low[maxn];
int fath[maxn];
bool vis[maxn];
bool maps[maxn][maxn];
int n, tol, cnt; void init() {
cnt = tol= ;
memset(dfn, , sizeof(dfn));
memset(low, , sizeof(low));
memset(maps, , sizeof(maps));
memset(fath, , sizeof(fath));
memset(head, -, sizeof(head));
memset(vis, false, sizeof(vis));
} void addnode(int u, int v) {
node[tol].u = u;
node[tol].v = v;
node[tol].next = head[u];
head[u] = tol++;
} void dfs(int u, int fa){
fath[u] = fa;
low[u] = dfn[u] = ++cnt;
vis[u] = true;
for(int i=head[u]; i!=-; i=node[i].next) {
int v = node[i].v;
if(!dfn[v]) {
dfs(v, u);
low[u] = min(low[u], low[v]);
} else if(v != fa) {
low[u] = min(low[u], dfn[v]);
}
}
} void tarjan() {
for(int u=; u<n; u++) {
if(!dfn[u]) {
dfs(u, u);
}
}
} bool cmp(Edge a, Edge b) {
if(a.u == b.u)
return a.v < b.v;
else
return a.u < b.u;
} void solve() {
tol = ;
for(int u=; u<n; u++) {
int v = fath[u];
if(low[u] > dfn[v] && v != u) {
edge[tol].u = u;
edge[tol].v = v;
if(edge[tol].u > edge[tol].v)
swap(edge[tol].u, edge[tol].v);
tol++;
}
}
sort(edge, edge+tol, cmp);
printf("%d critical links\n", tol);
for(int i=; i<tol; i++) {
printf("%d - %d\n", edge[i].u, edge[i].v);
}
printf("\n");
} int main() {
while(scanf("%d", &n) != EOF) {
init();
if(n == ) {
printf("0 critical links\n\n");
continue;
}
for(int i=; i<=n; i++) {
int u;
int num;
scanf("%d (%d)", &u, &num);
for(int j=; j<=num; j++) {
int v;
scanf("%d", &v);
maps[u][v] = maps[v][u] = ;
}
}
for(int i=; i<n; i++) {
for(int j=i+; j<n; j++) {
if(maps[i][j]) {
addnode(i, j);
addnode(j, i);
}
}
}
tarjan();
solve();
}
return ;
}

Uva796 Critical Links的更多相关文章

  1. UVA796 Critical Links —— 割边(桥)

    题目链接:https://vjudge.net/problem/UVA-796 In a computer network a link L, which interconnects two serv ...

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

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

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

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

  4. UVA796 Critical Links(求桥) 题解

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

  5. UVA796 - Critical Links(Tarjan求桥)

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

  6. UVA796:Critical Links(输出桥)

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

  7. kuangbin专题 专题九 连通图 Critical Links UVA - 796

    题目链接:https://vjudge.net/problem/UVA-796 题目:裸的求桥,按第一个元素升序输出即可. #include <iostream> #include < ...

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

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

  9. UVA 796 Critical Links(Tarjan求桥)

    题目是PDF就没截图了 这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理 代码: #include <stdio.h> #include <bits/std ...

随机推荐

  1. React Native之code-push的热更新(ios android)

    React Native之code-push的热更新(ios android) React Native支持大家用React Native技术开发APP,并打包生成一个APP.在动态更新方面React ...

  2. mysql实现首字母从A-Z排序

    1.常规排序ASC DESC ASC 正序 DESC倒叙 -- 此处不用多讲 2.自定义排序 自定义排序是根据自己想要的特定字符串(数字)顺序进行排序.主要是使用函数 FIELD(str,str1,s ...

  3. [转帖]SAP一句话入门:Human Resource

    SAP一句话入门:Human Resource http://blog.vsharing.com/MilesForce/A621279.html HR这一句话,太简单了:组织.招聘.发工资.任职.考勤 ...

  4. yum仓库搭建

    1. 创建yum仓库目录 mkdir -p /application/yum/centos6.6/x86_64/ cd /application/yum/centos6.6/x86_64/ rz  # ...

  5. C#中is运算符

    is运算符可以检查对象是否与特定的类型兼容.“兼容”表示对象或者该类型,或者派生自该类型.例如,要检查变量是否与object类型兼容,可以使用下面的代码: int i=10; if(i  is  ob ...

  6. spring 标签

    */ @Slf4j @Service public class RetryService { @Autowired private MqConfig mqConfig; /** * 如果网络连接失败, ...

  7. WEX5中ajax跨域访问的几种方式

    1.使用jsonp方式 使用jsonp访问的话,前端需要把回调函数名传递给后端,后端执行完后也需要把回调函数传回给前端,默认情况下ajax自动生成一个回调函数名,后端可以通过String callba ...

  8. falsk 项目中日志设置

    app/__init__.py: 1 import logging from logging.handlers import RotatingFileHandler ''' 开发中使用DEBUG级别, ...

  9. Learning to Rank(转)

    https://blog.csdn.net/kunlong0909/article/details/16805889 Table of Contents 1 前言 2 LTR流程 3 训练数据的获取4 ...

  10. How to install Windows 7 SP1 on Skylake

    Download gigabyte windows usb installation tool http://www.gigabyte.cn/WebPage/-79/usb.html get Wind ...