时间复杂度: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树求割点问题的更多相关文章

  1. 【bzoj2115】[Wc2011] Xor DFS树+高斯消元求线性基

    题目描述 输入 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 Di的无向边. 图 ...

  2. Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)【转】【修改】

    一.基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成 ...

  3. (转)Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)

    基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成多个 ...

  4. uva 315 Network(无向图求割点)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. poj 1144 (Tarjan求割点数量)

    题目链接:http://poj.org/problem?id=1144 描述 一个电话线公司(简称TLC)正在建立一个新的电话线缆网络.他们连接了若干个地点分别从1到N编号.没有两个地点有相同的号码. ...

  6. UVA 315 Network (模板题)(无向图求割点)

    <题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...

  7. 求割点 割边 Tarjan

    附上一般讲得不错的博客 https://blog.csdn.net/lw277232240/article/details/73251092 https://www.cnblogs.com/colle ...

  8. (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. B - Network---UVA 315(无向图求割点)

        A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connectin ...

随机推荐

  1. pyqt QT设计师制作关于对话框(软件版权申明)

    一.实验环境 1.anaconda2 2.5.0 + python2.7 2.pyinstaller3.0 二.操作步骤 2.1 启动designer.exe 2.2 单击“文件” -> “新建 ...

  2. [leetcode] 300. Longest Increasing Subsequence (Medium)

    题意: 求最长增长的子序列的长度. 思路: 利用DP存取以i作为最大点的子序列长度. Runtime: 20 ms, faster than 35.21% of C++ online submissi ...

  3. sql server还原数据库(请选择用于还原的备份集)

    还原数据库的时候明明选择了备份集,还是提示未选择还原的备份集 后来查了下,是因为我本地有两个数据库(2008R2和2014),对应的两个数据库实例.而还原bak是sqlserver2014的备份,我默 ...

  4. js,ts操作dom总结

    以上面为例: js获取placeholder节点 : document.getElementsByClassName("newTicket")[0].getAttributeNod ...

  5. ORM详解

    讲解对象:ORM详解 作者:融水公子 rsgz 1 前言:开发流程正常只有简单的几步 0.1 配置数据库 0.2 定义模型 0.3 迁移文件 0.4 执行迁移生成数据表 0.5 使用模型类增删改查 2 ...

  6. 【Vue前端】Vue前端注册业务实现!!!【代码】

    用户注册前端逻辑 1. Vue绑定注册界面准备 1.导入Vue.js库和ajax请求的库 <script type="text/javascript" src="{ ...

  7. 在线图片base64编码

    图片Base64编码https://oktools.net/image2base64 在线工具https://oktools.net JSON格式化https://oktools.net/json U ...

  8. MRCPv2在电信智能语音识别业务中的应用

    1. MRCPv2协议简介 媒体资源控制协议(Media Resource Control Protocol, MRCP)是一种基于TCP/IP的通讯协议,用于客户端向媒体资源服务器请求提供各种媒体资 ...

  9. 9-1、大型项目的接口自动化实践记录----数据库结果、JSON对比

    上一篇写了如何从DB获取预期.实际结果,这一篇分别对不同情况说下怎么进行对比. PS:这部分在JSON对比中也适用. 1.结果只有一张表,只有一条数据 数据格式:因为返回的是dicts_list的格式 ...

  10. 记一次使用LR测试UDP和TCP的过程

    背景 最近项目要做性能测试,要出要一份性能报告,让我出一个有关Tcp和Udp的功能模块的测试,流程大概是这样,先走TCP协议协商一下会话,协商成功后走Udp收发数据. 有点简单啊,自己写个功能模块测一 ...