图论--割点--Tarjan模板
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
using namespace std;
const int N=100010;
int head[N],ver[N*2],Next[N*2];
int dfn[N],low[N],n,m,tot,num;
bool brige[N*2];
void add(int x,int y){
ver[++tot]=y,Next[tot]=head[x],head[x]=tot;
}
void tarjan(int x,int inedge)
{
dfn[x]=low[x]=++num;
for(int i=head[x];i;i=Next[i])
{
int y=ver[i];
if(!dfn[y])
{
tarjan(y,i);
low[x]=min(low[x],low[y]);
if(low[y]>dfn[x])
{
brige[i]=brige[i^1]=1;
}
}
else if(i!=(inedge^1))
low[x]=min(low[x],dfn[y]);
}
}
int main()
{
cin>>n>>m;
tot=1;
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d %d",&x,&y);
add(x,y);
add(y,x);
}
for(int i=1 ;i<=n;i++)
if(!dfn[i]) tarjan(i,0);
int ans=0;
for(int i=2;i<tot;i+=2)
{
if(brige[i])
{
printf("%d %d\n",ver[i^1],ver[i]);
}
}
}
图论--割点--Tarjan模板的更多相关文章
- 图论算法-Tarjan模板 【缩点;割顶;双连通分量】
图论算法-Tarjan模板 [缩点:割顶:双连通分量] 为小伙伴们总结的Tarjan三大算法 Tarjan缩点(求强连通分量) int n; int low[100010],dfn[100010]; ...
- 图论--割边--Tarjan模板
#include<iostream> #include<stdio.h> #include<vector> using namespace std; const i ...
- 图论--割点--Tarjan
#include<iostream> #include<stdio.h> #include<vector> using namespace std; const i ...
- 洛谷3388 【模板】割点 tarjan算法
题目描述 给出一个n个点,m条边的无向图,求图的割点. 关于割点 在无向连通图中,如果将其中一个点以及所有连接该点的边去掉,图就不再连通,那么这个点就叫做割点(cut vertex / articul ...
- poj 1523 割点 tarjan
Description Consider the two networks shown below. Assuming that data moves around these networks on ...
- 学渣乱搞系列之Tarjan模板合集
学渣乱搞系列之Tarjan模板合集 by 狂徒归来 一.求强连通子图 #include <iostream> #include <cstdio> #include <cs ...
- UOJ #146. 【NOIP2015】信息传递 连通分量 tarjan模板题
http://uoj.ac/problem/146 题解:强连通分量 tarjan模板题.同时试了一下codeblock #include<bits/stdc++.h> using nam ...
- 洛谷1726 上白泽慧音 tarjan模板
题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...
- 算法问题实战策略 MEETINGROOM 附一份tarjan模板
地址 https://algospot.com/judge/problem/read/MEETINGROOM 解答 2-sat 代码样例过了 没有ac. 我又没有正确代码对拍..... 已确认是输出 ...
随机推荐
- Typora+PicGo+GitHub实现md自带图床效果
1 GitHub创建作为图床的仓库 1.1 在GitHub中创建一个仓库 注意仓库要是public的,不然上传的图片还是无法使用的.如果不知道怎么创建仓库,可以百度一下. 1.2 在GitHub生成一 ...
- 31.3 自定义异常类 MyException
/* * 异常的分类: 运行时期异常:RuntimeException的子类就是运行时期异常,在编译时期可以自由选择处理或者不处理 编译时期异常:是Exception的子类,非RuntimeExcpe ...
- golang开发:环境篇(七) Go mod 使用
Glide用的好好的,为什么要使用Modules 在 Go 1.11 中 ,官方加入package management tool,称为Go Modules.Go mod 没有出现之前,用的最多的包管 ...
- "Tag标签"组件:<tags> —— 快应用组件库H-UI
 <import name="tags" src="../Common/ui/h-ui/text/c_tags"></import> ...
- python3(二十一) pip
先确保安装了windows的Python的pip 出现上图说明安装了,命令未找到则没有安装 安装一个图形处理的第三方库 Anaconda安装第三方库 我们经常需要用到很多第三方库,如MySQL驱动程序 ...
- tf.nn.relu 激活函数
tf.nn.relu(features, name = None) 计算校正线性:max(features, 0) 参数: features:一个Tensor.必须是下列类型之一:float32,fl ...
- MyBatis通用 Mapper4使用小结
官网地址: http://www.mybatis.tk/ https://gitee.com/free 1.使用springboot,添加依赖: 使用tk的mybatis后不需要引用官方原生的myba ...
- IO流学习总结
IO: 概述: IO流用来处理设备之间的数据传输,如上传文件和下载文件 Java对数据的操作是通过流的方式 Java用于操作流的对象都在IO包中按照数据流向: 输入流 读入数据 从操作系统上读入文件到 ...
- AJ学IOS 之ipad开发Popover的调色板应用_popover显示后其他控件仍然能进行交互
AJ分享,必须精品 一:效果 后面的是xcode的控制台 二:代码 ViewController #import "ViewController.h" #import " ...
- SpringBoot事件监听机制源码分析(上) SpringBoot源码(九)
SpringBoot中文注释项目Github地址: https://github.com/yuanmabiji/spring-boot-2.1.0.RELEASE 本篇接 SpringApplicat ...