P3388 【模板】割点(割顶)

题目背景

割点

题目描述

给出一个n个点,m条边的无向图,求图的割点。

输入输出格式

输入格式:

第一行输入n,m

下面m行每行输入x,y表示x到y有一条边

输出格式:

第一行输出割点个数

第二行按照节点编号从小到大输出节点,用空格隔开

输入输出样例

输入样例#1: 复制

6 7
1 2
1 3
1 4
2 5
3 5
4 5
5 6
输出样例#1: 复制

1
5

说明

n,m均为100000

tarjan 图不一定联通!!!

分析

tarjan求割点

code

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib> using namespace std; const int N = ;
struct Edge{
int to,nxt;
}e[N<<];
int head[N],dfn[N],low[N];
bool iscut[N];
int tn,tot; inline char nc() {
static char buf[],*p1 = buf,*p2 = buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,,,stdin),p1==p2) ? EOF : *p1++;
}
inline int read() {
int x = ,f = ;char ch = nc();
for (; ch<''||ch>''; ch = nc())
if (ch=='-') f = -;
for (; ch>=''&&ch<=''; ch = nc())
x = x*+ch-'';
return x * f;
} void add_edge(int u,int v) {
e[++tot].to = v,e[tot].nxt = head[u],head[u] = tot;
} void tarjan(int u,int fa) {
low[u] = dfn[u] = ++tn;
int cnt_son = ;
for (int i=head[u]; i; i=e[i].nxt) {
int v = e[i].to;
if (!dfn[v]) {
cnt_son++;
tarjan(v,u);
low[u] = min(low[u],low[v]);
if (low[v] >= dfn[u])
iscut[u] = true;
}
else if (dfn[v] < dfn[u] && v != fa)
low[u] = min(low[u],dfn[v]);
}
if (fa< && cnt_son==) iscut[u] = false;
}
int main() {
int n = read(),m = read();
for (int u,v,i=; i<=m; ++i) {
u = read(),v = read();
add_edge(u,v),add_edge(v,u);
}
for (int i=; i<=n; ++i)
if (!dfn[i]) tarjan(i,-); int ans = ;
for (int i=; i<=n; ++i)
if (iscut[i]) ans++;
printf("%d\n",ans);
for (int i=; i<=n; ++i)
if (iscut[i]) printf("%d ",i);
return ;
}

P3388 【模板】割点(割顶)的更多相关文章

  1. Tarjan求割点(割顶) 割边(桥)

    割点的定义: 感性理解,所谓割点就是在无向连通图中去掉这个点和所有和这个点有关的边之后,原先连通的块就会相互分离变成至少两个分离的连通块的点. 举个例子: 图中的4号点就是割点,因为去掉4号点和有关边 ...

  2. $割点割顶tarjan$

    原题 #include <bits/stdc++.h> using namespace std; typedef long long LL; inline LL read () { LL ...

  3. 洛谷 P3388 割点(割顶) 题解

    题面:     割点性质:     节点 u 如果是割点,当且仅当存在 u 的一个子树,子树中没有连向 u 的祖先的边(返祖边).     换句话说,如果对于一个点u,它的子节点是v,如果low[v] ...

  4. Tarjan求割点 || Luogu P3388 【模板】割点(割顶)

    题面:P3388 [模板]割点(割顶) 题解:无 代码: #include<cstdio> #include<iostream> #include<cstring> ...

  5. P3388 【模板】割点(割顶) 题解 (Tarjan)

    题目链接 P3388 [模板]割点(割顶) 解题思路 最近学的东西太杂了,多写点博客免得自己糊里糊涂的过去了. 这个题求割点,感觉这篇文章写得挺好. 割点是啥?如果去掉这个点之后连通图变成多个不连通图 ...

  6. 洛谷 P3388 【模板】割点(割顶)(Tarjan)

    题目链接 https://www.luogu.org/problemnew/show/P3388 模板题 解题思路 什么是割点? 怎样求割点? dfn :即时间戳,一张图的dfs序(dfs遍历时出现的 ...

  7. 图论算法-Tarjan模板 【缩点;割顶;双连通分量】

    图论算法-Tarjan模板 [缩点:割顶:双连通分量] 为小伙伴们总结的Tarjan三大算法 Tarjan缩点(求强连通分量) int n; int low[100010],dfn[100010]; ...

  8. poj 1144 Network 图的割顶判断模板

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8797   Accepted: 4116 Descripti ...

  9. POJ 1144 Network(无向图的割顶和桥模板题)

    http://poj.org/problem?id=1144 题意: 给出图,求割点数. 思路: 关于无向图的割顶和桥,这篇博客写的挺不错,有不懂的可以去看一下http://blog.csdn.net ...

随机推荐

  1. eclipse下 Failed to find an AVD compatible with target 的解决方法

    第一个Android测试环境下的程序出现这个问题: [2012-04-24 13:18:29 - xxxx] ------------------------------ [2012-04-24 13 ...

  2. Mvc异常处理器

    using System; using System.Text; using EMS.Domains.Core; using System.Web.Mvc; using Json.Net; using ...

  3. Array.isArray() 和 isObject() 原生js实现

    function isObject(val) { return val != null && typeof val === 'object' && Array.isAr ...

  4. CRC检错技术原理

    一.题外话 说来惭愧,一开始是考虑写关于CRC检错技术更深层次数学原理的,然而在翻看<Basic Algebra>后,我果断放弃了这种不切实际的想法.个人觉得不是因为本人数学水平差或者能力 ...

  5. POJ 1185 炮兵阵地 (状压DP,轮廓线DP)

    题意: 给一个n*m的矩阵,每个格子中有'P'或者'H',分别表示平地和高原,平地可以摆放大炮,而大炮的攻击范围在4个方向都是2格(除了自身位置),攻击范围内不能有其他炮,问最多能放多少个炮?(n&l ...

  6. HDU 2188 悼念512汶川大地震遇难同胞——选拔志愿者(巴什博弈)

    思路:若能给对方留下m+1,就可以胜.否则败. #include <iostream> using namespace std; int main() { int t,n,m;cin> ...

  7. python爬虫之路——构造URL集

    例某网站的URL集是这样的 https://www.555zw.com/book/40/40934/10334793.html https://www.555zw.com/book/40/40934/ ...

  8. ABAP和Java单例模式的攻防

    ABAP CLASS zcl_jerry_singleton DEFINITION PUBLIC FINAL CREATE PRIVATE . PUBLIC SECTION. INTERFACES i ...

  9. 【UML】协作图Collaboration diagram(交互图)(转)

    http://blog.csdn.net/sds15732622190/article/details/49402269 前言         学完UML时序图,就要看一下UML协作图,因为两张图是相 ...

  10. [视觉] 基于YoloV3的实时摄像头记牌器

    基于YoloV3的实时摄像头记牌器 github:https://github.com/aoru45/cards_recognition_recorder_pytorch 最终效果 数据准备 数据获取 ...