Uva796 Critical Links
用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的更多相关文章
- UVA796 Critical Links —— 割边(桥)
题目链接:https://vjudge.net/problem/UVA-796 In a computer network a link L, which interconnects two serv ...
- uva-796.critical links(连通图的桥)
本题大意:求出一个无向图的桥的个数并且按照顺序输出所有桥. 本题思路:注意判重就行了,就是一个桥的裸题. 判重思路目前知道的有两种,第一种是哈希判重,第二种和邻接矩阵的优化一样,就是只存图的上半角或者 ...
- [UVA796]Critical Links(割边, 桥)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA796 Critical Links(求桥) 题解
题意:求桥 思路:求桥的条件是:(u,v)是父子边时 low[v]>dfn[u] 所以我们要解决的问题是怎么判断u,v是父子边(也叫树枝边).我们在进行dfs的时候,要加入一个fa表示当前进行搜 ...
- UVA796 - Critical Links(Tarjan求桥)
In a computer network a link L, which interconnects two servers, is considered critical if there are ...
- UVA796:Critical Links(输出桥)
Critical Links 题目链接:https://vjudge.net/problem/UVA-796 Description: In a computer network a link L, ...
- kuangbin专题 专题九 连通图 Critical Links UVA - 796
题目链接:https://vjudge.net/problem/UVA-796 题目:裸的求桥,按第一个元素升序输出即可. #include <iostream> #include < ...
- Light OJ 1026 - Critical Links (图论-双向图tarjan求割边,桥)
题目大意:双向联通图, 现在求减少任意一边使图的联通性改变,按照起点从小到大列出所有这样的边 解题思路:双向边模版题 tarjan算法 代码如下: #include<bits/stdc++.h& ...
- UVA 796 Critical Links(Tarjan求桥)
题目是PDF就没截图了 这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理 代码: #include <stdio.h> #include <bits/std ...
随机推荐
- MySQL数据库导入错误:ERROR 1064 (42000) 和 ERROR at line xx:
https://www.cnblogs.com/yeahgis/p/4358973.html mysql -hlocalhost -uroot -proot --default-character-s ...
- oracle小记:dba_data_files
今天给表空间扩展的时候,使用了dba_data_files进行查询.查阅了网上的资料. 该系统系统中含有以下字段 每个字段的含义如下:
- 三、Object 对象常用操作方法
Object 构造方法 一.asign vs 扩展运算符 ... 1.共同点:都是浅拷贝 2.开发推荐 扩展运算符... let obj={ name: 'Tom', age: 18 }; let o ...
- vscode开发中绝对让你惊艳的插件!!!(个人在用)
识别模版引擎 1.Apache Velocity :识别Velocity(vm) 2.Art Template Helper:识别artTemplate 点击路径跳转 1.Laravel goto v ...
- Effective C++目录
条款1:视C++为一个语言联邦 条款2:尽量以const.enum.inline替换#define 条款3:尽可能使用const 条款4:确定对象使用前已先被初始化 条款5:了解C++默认编写并调用哪 ...
- 6s ios9.0平台 微信小程序的fixed定位兼容性问题
如果不设置top和left的话 就会出现不显示问题
- MySQL最大连接数设置
在使用MySQL数据库的时候,经常会遇到这么一个问题,就是“Can not connect to MySQL server. Too many connections”-mysql 1040错误,这是 ...
- yield send 的一些使用细节
其实日常中我们使用最多的是 return 很少会使用到 yield 去创造一个生成器.一般就是算算算 算完之后用 return 返回一把. 但是有些情况下 比如需要节约内存不需要一把全部返回,每次使用 ...
- C#后台绑定select
- 实体类注解错误:Could not determine type for: java.util.List
今天配置实体类注解时,出现以下错误: Caused by: org.hibernate.MappingException: Could not determine type for: java.uti ...