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 ...
随机推荐
- Windows下ElasticSearch的Head安装及基本使用
前段时间,有一朋友咨询我,说es的head插件一直安装失败,为了给朋友解惑,自己百度博文并实践了一番,也的确踩了些坑,但我给爬了起来.今天就来分享下实践心得并跳过的坑. ElasticSearch 是 ...
- JAVA通过URL链接获取视频文件信息(无需下载文件)
最近项目碰到一个大坑:APP上需要在获取视频列表时就获取视频的时长,但早期上传的时候数据库都没有保存这个数据,所以前段时间添加一个时长字段,在上传时手动输入视频时长,但是之前库中有上万条数据没这个信息 ...
- Excel催化剂开源第13波-VSTO开发之DataGridView控件几个小坑
Excel催化剂内部大量使用了DataGridView,这其中有一些小坑,花了力气才解决的,在此给广大开发者作简单分享. 为何要使用DataGridView而不是其他控件如ListBox.ListVi ...
- Excel催化剂开源第9波-VSTO开发图片插入功能,图片带事件
图片插入功能,这个是Excel插件的一大刚需,但目前在VBA接口里开发,如果用Shapes.AddPicture方法插入的图片,没法对其添加事件,且图片插入后需等比例调整纵横比例特别麻烦,特别是对于插 ...
- Hive之函数与自定义函数
系统自带的函数 1)查看系统自带的函数 hive> show functions; 2)显示自带的函数的用法 hive> desc function upper; 3)详细显示自带的函数的 ...
- 安科 OJ 1190 连接电脑 (并查集)
时间限制:1 s 空间限制:128 M 传送门:https://oj.ahstu.cc/JudgeOnline/problem.php?id=1190 题目描述 机房里有若干台电脑,其中有一些电脑已经 ...
- 《VR入门系列教程》之19---GearVR开发初识
本章我们来介绍一下如何在移动VR设备的佼佼者GearVR上进行开发,之前我们在桌面端的VR开发想法可以直接应用在移动端,但是仍然会有些不一样的技术需要注意.这次,我们仍然采用Unity3D引擎构建示例 ...
- PHP-1.数据库连接与登陆
<?php //数据库信息 $servername = "localhost"; $username = "root"; $password = &quo ...
- 实现一个Golang的reverse函数
Reverse函数,用来反转列表,本例子用golang实现,反转一个slice列表. 因为slice是引用类型,因此直接修改参数的值即可. func myReverse(l []string) { f ...
- Ping、Traceroute工作原理
在工作开发过程中,我们经常会使用到ping和traceroute.在这里,我们将细述其工作原理,让你在会用的基础之上理解其内部工作过程. ICMP应用实例--Ping Ping 是 ICMP 的一个重 ...