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 ...
随机推荐
- 开发板编译./camera显示-/bin/sh: ./camera: not found解决方案
问题: 开发板根文件系统目录: 运行./camera显示: 问题解决: 1.排除根目录路径问题: 2. 加入静态链接库即无问题,但是编译后的".o"文件大小突增,而且也不可能每次编 ...
- 小白开学Asp.Net Core 《九》
小白开学Asp.Net Core <九> — — 前端篇(不务正业) 在<小白开学Asp.Net Core 三>中使用了X-admin 2.x 和 Layui将管理后端的界面重 ...
- java读写文件小心缓存数组
一般我们读写文件的时候都是这么写的,看着没问题哈. public static void main(String[] args) throws Exception { FileInputStr ...
- CentOS7源码安装Nginx
系统平台:腾讯云服务器 CentOS 7.3 64位 一.安装编译工具及库文件 [root@VM_0_5_centos ~]# yum install -y make zlib zlib-devel ...
- jsp数据交互(二).1
对象的作用域: JSP中提供了四种作用域,分别是page作用域,request作用域,session作用域和application作用域. page作用域: page作用域指单一JSP页面的范围, ...
- 提升10倍生产力:IDEA远程一键部署SpringBoot到Docker
作者:陶章好 juejin.im/post/5d026212f265da1b8608828b 推荐阅读(点击即可跳转阅读) 1. SpringBoot内容聚合 2. 面试题内容聚合 3. 设计模式内容 ...
- Docker 安装部署Sql Server
前言 在如今,容器化概念越来越盛行,.Net Core项目也可以跨平台部署了,那么思考下Sql Server能不能呢?当然是可以的啦.本文今天就是介绍Docker部署配置和连接Sql Server.本 ...
- Ubuntu 下jdk的安装
因为我ubuntu下需要运行一个java程序,其实是想做一下tc,因为浏览器要运行java插件,那个客户端一直下载不了,我记得我装过的,这个问题后面说.然后我就打算重新安装,通过查找资料,终于解决了手 ...
- 刷脸即可解锁让iDevice取证不再难如登天
最近有则取证相关的消息,链接如下,光看标题便知道与Apple的Face ID有关. https://www.cnet.com/news/fbi-unlocked-an-iphone-x-by-forc ...
- tcp四次挥手为什么要等待2MSL
之前所说了解有两个原因: 1.防止客户端最后一次发给服务器的确认在网络中丢失以至于客户端关闭,而服务端并未关闭,导致资源的浪费. 2.等待最大的2msl可以让本次连接的所有的网络包在链路上消失,以防造 ...