(连通图 模板题 无向图求桥)Critical Links -- UVA -- 796
链接:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82833#problem/C
说实话还不是太懂,自己再写点题理解理解!
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define N 1005 struct Edge{int v, next;}e[N*N];
struct Bridge{int u, v;}bri[N]; int bnt, n;
int Head[N], cnt;
int dfn[N], low[N], f[N], Index; bool cmp(Bridge a, Bridge b)
{
if(a.u != b.u)
return a.u < b.u;
return a.v < b.v;
} void Init()
{
cnt = bnt = Index = ;
memset(low, , sizeof(low));
memset(dfn, , sizeof(dfn));
memset(f, , sizeof(f)); for(int i=; i<=n; i++)
{
Head[i] = -;
dfn[i] = ;
}
} void AddEdge(int u, int v)
{
e[cnt].v = v;
e[cnt].next = Head[u];
Head[u] = cnt++;
} void TarJan(int u, int fa)
{
f[u] = fa;
low[u] = dfn[u] = ++Index; for(int j=Head[u]; j!=-; j=e[j].next)
{
int v = e[j].v; if(!dfn[v])
{
TarJan(v, u);
low[u] = min(low[u], low[v]);
}
else if(v!=fa)
low[u] = min(low[u], dfn[v]);
}
} int main()
{
while(scanf("%d", &n)!=EOF)
{
int i, j, u, v, m; Init(); for(i=; i<n; i++)
{
scanf("%d (%d)", &u, &m); for(j=; j<m; j++)
{
scanf("%d", &v);
AddEdge(u, v);
}
} for(i=; i<n; i++)
{
if(!dfn[i])
TarJan(i, i);
} for(i=; i<n; i++)
{
int u = f[i];
if(low[i] > dfn[u])
{
bri[bnt].u = min(u, i);
bri[bnt++].v = max(u, i);
}
} sort(bri, bri+bnt, cmp); printf("%d critical links\n", bnt); for(i=; i<bnt; i++)
printf("%d - %d\n", bri[i].u, bri[i].v);
printf("\n");
}
return ;
}
(连通图 模板题 无向图求桥)Critical Links -- UVA -- 796的更多相关文章
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- C - Critical Links - uva 796(求桥)
题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...
- kuangbin专题 专题九 连通图 Critical Links UVA - 796
题目链接:https://vjudge.net/problem/UVA-796 题目:裸的求桥,按第一个元素升序输出即可. #include <iostream> #include < ...
- [kuangbin带你飞]专题九 连通图C - Critical Links UVA - 796
这道题就是要求桥的个数. 那么桥相应的也有判定的定理: 在和u相邻的节点中,存在一个节点是最小的时间戳都比 当前u的访问次序要大,也就是说这个点是只能通过果u到达,那么 他们之间相邻的边就是的桥 #i ...
- UVA 796 Critical Links(模板题)(无向图求桥)
<题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...
- UVA 796 Critical Links(无向图求桥)
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号 (与这个点相连的点的个数m) 依次是m个点的 输入到文件结束. 桥输出的时候需要排序 知识汇总: 桥: 无向连通 ...
- 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D
目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...
- HDU 4738--Caocao's Bridges(重边无向图求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- uva 796 Critical Links(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- 使用CXF发布的WebService报错:org.apache.cxf.interceptor.Fault: The given SOAPAction does not match an operation
场景:JAVA语言使用CXF搭建WebService发布报错 错误信息:org.apache.cxf.interceptor.Fault: The given SOAPAction does not ...
- The requested resource (/) is not available解决办法
The requested resource (/) is not available HTTP Status 404(The requested resource is not available) ...
- Spring/AOP框架, 以及使用注解
1, 使用代理增加日志, 也是基于最原始的办法 import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; ...
- ThreadPoolExecutor的execute源码分析
上一篇文章指出,ThreadPoolExecutor执行的步骤如下: 向线程池中添加任务,当任务数量少于corePoolSize时,会自动创建thead来处理这些任务: 当添加任务数大于corePoo ...
- Date.parse和new Date(str)的兼容性问题
Date.parse和new Date(str)的兼容性问题 Date '2015-05-04'是无法被各个浏览器中,使用new Date(str)来正确生成日期对象的. 正确的用法是'2015/05 ...
- Saving Tang Monk II(bfs+优先队列)
Saving Tang Monk II https://hihocoder.com/problemset/problem/1828 时间限制:1000ms 单点时限:1000ms 内存限制:256MB ...
- Spring AOP开发
--------------------siwuxie095 Spring AOP 开发 1.在 Spring 中进行 ...
- Django的cookie学习
为什么要有cookie,因为http是无状态的,每次请求都是独立的,但是我们还需要保持状态,所以就有了cookie cookie就是保存在客户端浏览器上的键值对,别人可以利用他来做登陆 rep = r ...
- django的视图函数介绍
我们来看下views视图中的函数的request这个变量到底有哪些方法和属性 1.request.path 结果:不包括域名和端口的url路径 2.request.method 结果:这次请求的方法, ...
- 两个应用之间传递广播的规则 Broadcast
sendBroadcast(new Intent(Config.ACTION_PRINT),”com.qf.permission.print”);先判断应用有没有对应的权限 再去判断有没有对应的act ...