【luogu P3388 割点(割顶)】 模板
题目链接:https://www.luogu.org/problemnew/show/P3388
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 500000 + 10;
ll n, m, ans;
ll dfn[maxn], low[maxn], tim;
bool iscut[maxn];
struct edge{
ll from, to, next;
}e[maxn<<2];
ll head[maxn], cnt;
void add(ll u, ll v)
{
e[++cnt].from = u;
e[cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
void tarjan(ll x, ll fa)
{
ll child = 0;
dfn[x] = low[x] = ++tim;
for(ll i = head[x]; i != -1; i = e[i].next)
{
ll v = e[i].to;
if(!dfn[v])
{
tarjan(v,fa);
low[x] = min(low[x], low[v]);
if(low[v] >= dfn[x] && x != fa) iscut[x] = 1;
if(x == fa) child++;
}
low[x] = min(low[x], dfn[v]);
}
if(x == fa && child >= 2) iscut[fa] = 1;
}
int main()
{
freopen("testdata.in","r",stdin);
freopen("qwq.txt","w",stdout);
memset(head, -1, sizeof(head));
scanf("%lld%lld",&n,&m);
for(ll i = 1; i <= m; i++)
{
ll u, v;
scanf("%lld%lld",&u,&v);
add(u,v),add(v,u);
}
for(ll i = 1; i <= n; i++)
if(!dfn[i]) tarjan(i,i);
for(ll i = 1; i <= n; i++)
if(iscut[i] == 1) ans++;
printf("%lld\n",ans);
for(ll i = 1; i <= n; i++)
if(iscut[i] == 1)printf("%lld ",i);
return 0;
}
【luogu P3388 割点(割顶)】 模板的更多相关文章
- 洛谷 P3388 割点(割顶) 题解
题面: 割点性质: 节点 u 如果是割点,当且仅当存在 u 的一个子树,子树中没有连向 u 的祖先的边(返祖边). 换句话说,如果对于一个点u,它的子节点是v,如果low[v] ...
- Tarjan求割点(割顶) 割边(桥)
割点的定义: 感性理解,所谓割点就是在无向连通图中去掉这个点和所有和这个点有关的边之后,原先连通的块就会相互分离变成至少两个分离的连通块的点. 举个例子: 图中的4号点就是割点,因为去掉4号点和有关边 ...
- $割点割顶tarjan$
原题 #include <bits/stdc++.h> using namespace std; typedef long long LL; inline LL read () { LL ...
- Tarjan求割点 || Luogu P3388 【模板】割点(割顶)
题面:P3388 [模板]割点(割顶) 题解:无 代码: #include<cstdio> #include<iostream> #include<cstring> ...
- P3388 【模板】割点(割顶)
P3388 [模板]割点(割顶) 题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式 ...
- P3388 【模板】割点(割顶) 题解 (Tarjan)
题目链接 P3388 [模板]割点(割顶) 解题思路 最近学的东西太杂了,多写点博客免得自己糊里糊涂的过去了. 这个题求割点,感觉这篇文章写得挺好. 割点是啥?如果去掉这个点之后连通图变成多个不连通图 ...
- 【Luogu P3388】割点模板
Luogu P3388 在一个无向图中,如果有一个顶点集合,删除这个顶点集合以及这个集合中所有顶点相关联的边以后,图的连通分量增多,就称这个点集为割点集合. 如果某个割点集合只含有一个顶点X(也即{X ...
- 图论算法-Tarjan模板 【缩点;割顶;双连通分量】
图论算法-Tarjan模板 [缩点:割顶:双连通分量] 为小伙伴们总结的Tarjan三大算法 Tarjan缩点(求强连通分量) int n; int low[100010],dfn[100010]; ...
- poj 1144 Network 图的割顶判断模板
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8797 Accepted: 4116 Descripti ...
随机推荐
- Beam编程系列之Java SDK Quickstart(官网的推荐步骤)
不多说,直接上干货! https://beam.apache.org/get-started/beam-overview/ https://beam.apache.org/get-started/qu ...
- 在使用反射时,maven设置依赖范围引起的异常
背景是,运用annotation进行权限控制,将一个包下面的类.进行反射,然后判断类的annotation,根据annotation设置权限 问题来了,包下面有5个类,在反射时报了 javqx.ser ...
- TOJ 2861 Octal Fractions
描述 Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0 ...
- swpuctf-web部分学习总结
1.用优惠码 买个 X ? (1)第一步: 这道题第一步主要知道利用php的随机种子数泄露以后就可以利用该种子数来预测序列,而在题目中会返回15位的优惠码,但是必须要24位的优惠码,因此要根据15位的 ...
- 强哥的分享--如何使用Spring Boot做一个邮件系统
http://springboot.fun/ actuator是单机.集群环境下要使用Spring Boot Admin将各个单机的actuator集成越来 mvn clean package -Dm ...
- 从数据库中导出数据到.csv文件
考虑到csv文件比xls文件格式容易控制,所以在这次导出中用的是.csv格式. protected function exportInfo($arr, &$err){ $nameInfo = ...
- [LeetCode]27. Remove Element移除元素
Given an array nums and a value val, remove all instances of that value in-place and return the new ...
- PAT 1055 The World's Richest
#include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #i ...
- jquery获取不了ajax动态添加的内容的解决办法
在HTML页面的一个button <div class="ajaxClick"> <button>内容</button> </div> ...
- .NET开源工作流RoadFlow-表单设计-按钮
在表单中添加一个按钮: 宽度,高度:按钮的宽度和高度. 文本:按钮显示的文本. 事件:点击按钮执行的操作.