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 ...
随机推荐
- Handling duplicate form submission in Spring MVC
javaweb开发之防止表单重复提交 - u012843873的博客 - CSDN博客 https://blog.csdn.net/u012843873/article/details/5526212 ...
- redux模块化demo
store.js 在redux中 store 是唯一的. import {createStore} from 'redux'; import reducer from './reducer' // 引 ...
- 如何入门vue之二
学习完指令之后我们需要学习的就是组件. 在学习组件前我们要了解一下 methods 用来处理事件的. computed用来计算属性 他就是类似于data一样只不过是动态的处理数据 里面写的方法当成属 ...
- .Net在操作mysql查询的时候出现“: Unknown column 'UserName' in 'where clause'”错误
今天使用.Net操作mysql查询的时候,如果加上条件查询的时候就会出现 Unknown column 'UserName' in 'where clause'这个错,不加条件直接select * f ...
- RabbitMQ基本操作
更加详细的 链接https://www.cnblogs.com/dwlsxj/p/RabbitMQ.html RabbitMQ基础知识 一.背景 RabbitMQ是一个由erlang开发的AMQP(A ...
- Android——AsyncTask
AsyncTask简单介绍 我们首先需要明确Android之所以有Handler和AsyncTask,都是为了不阻塞主线程(UI线程),且UI的更新只能在主线程中完成,因此异步处理是不可避免的.And ...
- linux audit审计(8)--开启audit对系统性能的影响
我们使用测试性能的工具,unixbench,它有一下几项测试项目: Execl Throughput 每秒钟执行 execl 系统调用的次数 Pipe Throughput 一秒钟内一个进程向一个管道 ...
- Python——Radiobutton,Checkbutton参数说明
anchor : 文本位置: background(bg) : 背景色: foreground(fg) :前景色: borderwidth : 边框宽度: width : 组件的宽度: hei ...
- 实体类注解错误:Could not determine type for: java.util.List
今天配置实体类注解时,出现以下错误: Caused by: org.hibernate.MappingException: Could not determine type for: java.uti ...
- mesh函数
[t,W]=meshgrid([2:0.2:7],[0:pi/6:3*pi]); %设置时-频相平面网格点 Gs1=(1/(sqrt(2*pi)*a))*exp(-0.5*abs((t1-t)/a). ...