图论--割点--Tarjan
2024-09-07 11:09:15
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
const int maxn=100010;
int head[maxn],ver[maxn*2],Next[maxn*2];
int dfn[maxn],low[maxn],sta[maxn];
int n,m,tot,num,root;
bool cut[maxn];
void add(int x,int y)
{
ver[++tot]=y;
Next[tot]=head[x];
head[x]=tot;
}
void tarjan(int x)
{
dfn[x]=low[x]=++num;
int flag=0;
for(int i=head[x];i;i=Next[i])
{
int y=ver[i];
if(!dfn[y])
{
tarjan(y);
low[x]=min(low[x],low[y]);
if(low[y]>=dfn[x])
{
flag++;
if(x!=root||flag>1) cut[x]=1;
}
}
else 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);
if(x==y) continue;
add(x,y),add(y,x);
}
for(int i=1;i<=n;i++)
{
if(!dfn[i]) root=i,tarjan(i);
}
for(int i=1;i<=n;i++)
if(cut[i]) printf("%d ",i);
}
最新文章
- 三维网格分割算法(Random Walks)
- HttpClientHandler
- iOS开发中GCD在多线程方面的理解
- asp.net mvc Remote远程验证
- 图画(txt等一下)实施开放的默认下载的默认浏览器,而不是(Java文本)
- css3中display和box小结
- redis 队列缓存 + mysql 批量入库 + php 离线整合
- CentOS安装Nginx 报错“configure: error: the HTTP rewrite module requires the PCRE library”解决办法
- xShell终端下中文乱码问题
- 推荐系统——online(上)
- 阅读源码(III)
- PA 模块常用表2
- HashMap扩容全过程
- 从ranknet到lamdarank,再到lamdamart
- SSRS表达式里引用.net dll
- git 服务器安装流程
- Git 使用篇二:搭建远程服务器
- Dubbo配置优化
- Leetcode题库——28.实现strStr()
- annotation-config和component-scan