题目背景

割点

题目描述

给出一个nnn个点,mmm条边的无向图,求图的割点。

输入输出格式

输入格式:

第一行输入n,mn,mn,m

下面mmm行每行输入x,yx,yx,y表示xxx到yyy有一条边

输出格式:

第一行输出割点个数

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

输入输出样例

输入样例#1:
复制

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

1
5

说明

对于全部数据,n≤20000n \le 20000n≤20000,m≤100000m \le 100000m≤100000

点的编号均大于000小于等于nnn。

tarjan图不一定联通。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x3f3f3f3f
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ struct node {
int to,nxt;
}edge[maxn<<1];
int n, m;
int idx, cnt, tot;
int head[maxn], dnf[maxn], low[maxn];
bool cut[maxn]; void addedge(int u, int v) {
edge[++cnt].to = v;
edge[cnt].nxt= head[u]; head[u] = cnt;
}
void tarjan(int u, int fa) {
dnf[u] = low[u] = ++idx;
int ch = 0;
for (int i = head[u]; i; i = edge[i].nxt) {
int to = edge[i].to;
if (!dnf[to]) {
tarjan(to, fa);
low[u] = min(low[u], low[to]);
if (low[to] >= dnf[u] && u != fa) {
cut[u] = true;
}
if (u == fa)ch++;
}
low[u] = min(low[u], dnf[to]);
}
if (ch >= 2 && u == fa)cut[u] = true;
} int main()
{
//ios::sync_with_stdio(0);
rdint(n); rdint(m);
for (int i = 0; i < m; i++) {
int a, b;
rdint(a); rdint(b);
addedge(a, b); addedge(b, a); }
for (int i = 1; i <= n; i++) {
if (dnf[i] == 0)tarjan(i, i);
}
for (int i = 1; i <= n; i++) {
if (cut[i])tot++;
}
cout << tot << endl;
for (int i = 1; i <= n; i++) {
if (cut[i])cout << i << ' ';
}
return 0;
}

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

  1. $割点割顶tarjan$

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

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

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

  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. 图论算法-Tarjan模板 【缩点;割顶;双连通分量】

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

  7. P3388 【模板】割点(割顶)

    P3388 [模板]割点(割顶) 题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式 ...

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

    题目链接 题解 今天复习了一下割点. 关于\(tarjan\)这里不多讲 \(dfn\)和\(low\)数组的定义想必大家都知道 仔细观察一下,可以发现 假设便利\(u->v\)这条边 如果 \ ...

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

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

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

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

随机推荐

  1. oracle connect by用法篇 (包括树遍历)之一

    1.基本语法 select * from table [start with condition1] connect by [prior] id=parentid 一般用来查找存在父子关系的数据,也就 ...

  2. 类型:Java;问题:eclipse配置maven;结果:eclipse配置maven

    eclipse配置maven 下面跟大家分享的是eclipse配置maven的方法. 方法/步骤 安装maven之前,要先安装jdk及配置JAVA_HOME环境变量.JDK1.4以上. 下载maven ...

  3. 关于更新pip的心得

    如果pip install --upgrade pip 删除了自己,但是无法安装新的自己. 那么下载最新的pip,解压 1.在命令窗口输入  python(前提条件已经在系统路径)  setup.py ...

  4. java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory报错springmvc

    转自:https://blog.csdn.net/qq_41879385/article/details/82892555 下面是错误信息:java.lang.ClassNotFoundExcepti ...

  5. ORACLE体系结构一 (逻辑结构)-表空间、段、区和数据块

    一.Oracle的逻辑结构 Oracle的逻辑结构是一种层次结构.主要由:表空间.段.区和数据块等概念组成.逻辑结构是面向用户的,用户使用Oracle开发应用程序使用的就是逻辑结构.数据库存储层次结构 ...

  6. requestLayout, invalidate和postInvalidate的异同

    requestLayout 当一个VIEW的布局属性发生了变化的时候,可以调用该方法,让父VIEW调用onmeasure 和onlayout重新定位该view的位置,需要在UI线程调用 invalid ...

  7. windows 7 系统装机优化

    A:系统设置 1.控制面板\系统和安全\Windows Update\更改设置  把系统升级以及提示关闭      控制面板\系统和安全\Windows 防火墙\自定义设置 把专用网络和公共网络的防火 ...

  8. EZOJ #79

    传送门 分析 在经过若干次操作之后一定会产生一堆环 而我们又发现从一个点到另一个点实际可以经过所有环 于是问题就转换成了$k_1s_1 + k_2s_2 + ... + len = t$ 其中$s_i ...

  9. loj10131 暗的连锁

    传送门 分析 首先我们知道如果在一棵树上加一条边一定会构成一个环,而删掉环上任意一条边都不改变连通性.我们把这一性质扩展到这个题上不难发现如果一条树边不在任意一个新边构成的环里则删掉这条边之后可以删掉 ...

  10. Umbraco中如何找到home node

    在一个Umbraco项目中,我们经常会出现需要找到这个项目的home node的情况, 那么如何来找到项目的home node呢 方法如下: 1. 在View中 @inherits Umbraco.W ...