kuangbin专题 专题九 连通图 Critical Links UVA - 796
题目链接:https://vjudge.net/problem/UVA-796
题目:裸的求桥,按第一个元素升序输出即可。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define pb push_back
#define fi first
#define se second const int N = (int)1e3+;
int n,tot,tim;
int head[N],dfn[N],low[N];
struct node{
int to;
int nxt;
}e[N*N];
vector<pair<int,int> > cut; void init(){
for(int i = ; i <= n; ++i){
head[i] = -;
dfn[i] = ;
}
tim = tot = ;
} inline void add(int u,int v){
e[tot].to = v;
e[tot].nxt = head[u];
head[u] = tot++;
} void tarjan(int now,int pre){
dfn[now] = low[now] = ++tim;
int to;
for(int o = head[now]; ~o; o = e[o].nxt){
to = e[o].to;
if(to == pre) continue;//双向边的判断
if(!dfn[to]){
tarjan(to,now);
low[now] = min(low[now],low[to]);
//桥的条件
if(dfn[now] < low[to]) cut.pb(make_pair(min(now,to),max(now,to)));
}
else if(low[now] > dfn[to]) low[now] = dfn[to];
}
} void _ans(){ int ans = cut.size();
sort(cut.begin(),cut.end());
printf("%d critical links\n",ans);
for(int i = ; i < ans; ++i) printf("%d - %d\n",cut[i].fi,cut[i].se);
printf("\n");
cut.clear();
} int main(){ int u,v,m;
while(~scanf("%d",&n)){
init(); for(int i = ; i < n; ++i){
scanf("%d (%d)",&u,&m);
for(int j = ; j < m; ++j){
scanf("%d",&v);
add(u,v);
}
} for(int i = ; i < n; ++i) if(!dfn[i]) tarjan(i,i);
_ans();
} return ;
}
kuangbin专题 专题九 连通图 Critical Links UVA - 796的更多相关文章
- [kuangbin带你飞]专题九 连通图C - Critical Links UVA - 796
这道题就是要求桥的个数. 那么桥相应的也有判定的定理: 在和u相邻的节点中,存在一个节点是最小的时间戳都比 当前u的访问次序要大,也就是说这个点是只能通过果u到达,那么 他们之间相邻的边就是的桥 #i ...
- (连通图 模板题 无向图求桥)Critical Links -- UVA -- 796
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- C - Critical Links - uva 796(求桥)
题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...
- [kuangbin带你飞]专题九 连通图B - Network UVA - 315
判断割点的性质: 如果点y满足 low[y]>=dfn[x] 且不是根节点 或者是根节点,满足上述式子的有两个及其以上. 就是割点 如果是起点,那么至少需要两个子节点满足上述条件,因为它是根节点 ...
- [kuangbin带你飞]专题九 连通图
ID Origin Title 76 / 163 Problem A POJ 1236 Network of Schools 59 / 177 Problem B UVA 315 Ne ...
- 「kuangbin带你飞」专题十九 矩阵
layout: post title: 「kuangbin带你飞」专题十九 矩阵 author: "luowentaoaa" catalog: true tags: mathjax ...
- 给自己的小练习19-[kuangbin带你飞]专题九连通图
没有写题解.补一波 Network of Schools 问题1:求有向图中入度为0的点个数 问题2:使得整个图变成一个联通分量 问题1直接缩点统计 问题2=max(入度为0的点,出度为0的点),注意 ...
- uva 796 Critical Links(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 796 Critical Links(模板题)(无向图求桥)
<题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...
随机推荐
- ECMAScript基本语法——⑤运算符 算数运算符
+-*/%
- UVA - 12333 Revenge of Fibonacci (大数 字典树)
The well-known Fibonacci sequence is defined as following: F(0) = F(1) = 1 F(n) = F(n − 1) + F(n − 2 ...
- window10安装nginx及请求转发到tomcat服务器访问项目及开机自启
一.安装ngnix 1. 到nginx官网上下载相应的安装包,http://nginx.org/en/download.html: 下载进行解压,将解压后的文件放到自己心仪的目录下,我的解压文件放在 ...
- 设置Eclipse中的字符集为UTF-8
Eclipse 修改字符集 默认情况下 Eclipse 字符集为 GBK,但现在很多项目采用的是 UTF-8,这是我们就需要设置我们的 Eclipse 开发环境字符集为 UTF-8, 设置步骤如下: ...
- jdk 1.8.0_131 Class JavaLaunchHelper is implemented
错误提示:objc[49447]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jd ...
- java替换文件中某一行文本的内容
个人博客 地址:http://www.wenhaofan.com/article/20180913160442 代码如下 package com.wenhaofan.common.kit; impor ...
- javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
这个错误的原因是没有项目使用到了Tomcat中配置的数据源(但是你本地没有配置),关于什么是JNDI看这篇文章就够了® 今天导入一个项目(比较老的),在本地运行时报错: Cannot resolve ...
- 解决Oracle ORA-01033: ORACLE initialization or shutdown in progress错误 和 ORA-01589错误 要打开数据库则必须使用 RESETLOGS 或 NORESETLOGS 选项
要打开数据库则必须使用 RESETLOGS 或 NORESETLOGS 选项 SQL> startupORACLE 例程已经启动. Total System Global Area 13533 ...
- FOJ-2013 A Short Problem (前缀和)
Problem Description The description of this problem is very short. Now give you a string(length N), ...
- SaltStack之return与job管理
目录 1. SaltStack组件之return 1.1 return流程 1.2 使用mysql作为return存储方式 2. job cache 2.1 job cache流程 2.2 job管理 ...