DFS树求割点问题
时间复杂度:O(n玄学)总之不大
代码实现(好麻烦,蓝题变紫题)
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<bitset>
#include<set>
#include<string>
#if !defined(_WIN32)
#include<bits/stdc++.h>
#endif // !defined(_WIN32)
#define ll long long
#define dd double
using namespace std;
int n, m;
int tot;
ll ans;
struct edge
{
bool t;
bool flag;
int to;
int num;
int next;
}e[];
struct node
{
int son;
bool flag;
int f;
int head;
int d;
int deep;
}p[];
int vis[];
void add(int x, int y)
{
tot++;
e[tot].to = y;
e[tot].next = p[x].head;
p[x].head = tot;
}
bool check(int x)
{
for (int i = p[x].head; i; i = e[i].next)
{
if (e[i].flag && !e[i].t)
{
int to = e[i].to;
if (!(p[to].d < p[x].deep))
return ;
}
}
return ;
}
void dfs(int x, int f)
{
vis[x] = ;
p[x].deep = p[f].deep + ;
p[x].d = p[x].deep;
for (int i = p[x].head; i; i = e[i].next)
{
int to = e[i].to;
if (!vis[to])
{
p[x].son++;
p[to].f = x;
e[i].flag = ;
dfs(to, x);
}
}
}
void init(int x)
{
for (int i = p[x].head; i; i = e[i].next)
{
int to = e[i].to;
if (e[i].flag && !e[i].t)
{
init(to);
p[x].d = min(p[x].d, p[to].d);
}
}
}
void work()
{
for (int x = ; x <= n; x++)
{
if (x == )
{
if (p[x].son <= )
p[x].flag = ;
}
else if (p[x].son == )
{
p[x].flag = ;
}
else
{
if (check(x))
p[x].flag = ;
}
}
}
int main()
{
cin >> n >> m;
for (int i = ; i <= m; i++)
{
int x, y;
cin >> x >> y;
add(x, y);
add(y, x);
}
dfs(, );
for (int i = ; i <= n; i++)
{
for (int j = p[i].head; j; j = e[j].next)
{
int to = e[j].to;
if (!e[j].flag && to != p[i].f)
{
p[i].d = min(p[i].d, p[to].deep);
}
else if (to == p[i].f)
{
e[j].t = ;
}
}
}
init();
work();
for (int i = ; i <= n; i++)
{
if (!p[i].flag)
cout << i << endl;
}
return ;
}
DFS树求割点问题的更多相关文章
- 【bzoj2115】[Wc2011] Xor DFS树+高斯消元求线性基
题目描述 输入 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 Di的无向边. 图 ...
- Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)【转】【修改】
一.基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成 ...
- (转)Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)
基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成多个 ...
- uva 315 Network(无向图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- poj 1144 (Tarjan求割点数量)
题目链接:http://poj.org/problem?id=1144 描述 一个电话线公司(简称TLC)正在建立一个新的电话线缆网络.他们连接了若干个地点分别从1到N编号.没有两个地点有相同的号码. ...
- UVA 315 Network (模板题)(无向图求割点)
<题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...
- 求割点 割边 Tarjan
附上一般讲得不错的博客 https://blog.csdn.net/lw277232240/article/details/73251092 https://www.cnblogs.com/colle ...
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- B - Network---UVA 315(无向图求割点)
A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connectin ...
随机推荐
- python函数知识三 函数名的使用、格式化、递归
12.函数名的使用 函数是第一类对象 函数名可以当做值被赋值给变量 def func(): print(1) return a = func print(func) print(a) a() 函数名可 ...
- deque双端队列笔记
clear()clear()clear():清空队列 pushpushpush_back()back()back():从尾部插入一个元素. pushpushpush_front()front()fro ...
- CentOS 7.3 配置静态ip
镜像:CentOS-7-x86_64-DVD-1511.iso 1.修改.查看虚拟机的网段 1.1.查看虚拟机网段 编辑-> 虚拟机网络编辑器,修改的需要管理员权限 选择NAT模式 点击 NAT ...
- [二次编码,数据类型补充以及各种坑]https://i.cnblogs.com/EditPosts.aspx?postid=11184330
数据类型补充 str:不可变数据类型 1.capitalize首字母大写 name="song" n=name.capitalize() print(n) Song 2.title ...
- Vue的基本使用(一)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 《C# 语言学习笔记》——委托
委托是一种可以把引用存储为函数的类型. 委托的声明非常类似于函数,但不带函数体,且要使用delegate关键字.委托的声明制定了一个返回类型和一个参数列表. 在定义了委托后,就可以声明该委托类型的变量 ...
- Spring源码分析之环境搭建
写在最前面 最近突然心血来潮,想看看源码,看看大牛都怎么码代码,膜拜下.首选肯定是spring大法,于是说干就干,从GitHub上下载spring-framework源码编译拜读. 环境搭建 安装JD ...
- chapter01
1.请用命令查出ifconfig命令程序的绝对路径[root@localhost ~]# which ifconfig 答:/usr/sbin/ifconfig 2.请用命令展示以下命令哪些是内部命令 ...
- 【Android】Failed to convert @drawable/picture into a drawable
刚使用 eclipse 遇到了这个问题,图片的效果未显示出来,上网查找后发现这其实不算是问题:重启下工程或 eclipse 就行了. PS: 直接运行工程也可以,不影响效果.
- 记一次idea问题—performing vcs refresh...
01.前言 本人出现该场景是,我把本地SVN A项目删了,而A项目与B项目同在一个SVN目录下,当我修改B项目且提交代码时,出现了该问题. idea不是很懂操作,就搜索了一下得出了三种答案,但只有其一 ...