题目背景
割点
题目描述
给出一个 nn 个点,mm 条边的无向图,求图的割点。
输入格式
第一行输入两个正整数 n,mn,m。
下面 mm 行每行输入两个正整数 x,yx,y 表示 xx 到 yy 有一条边。
输出格式
第一行输出割点个数。
第二行按照节点编号从小到大输出节点,用空格隔开。
输入输出样例
输入 #1 复制
6 7
1 2
1 3
1 4
2 5
3 5
4 5
5 6
输出 #1 复制
1
5
说明/提示
对于全部数据,1\leq n \le 2\times 10^41≤n≤2×10
4
,1\leq m \le 10^51≤m≤10
5
。
点的编号均大于 00 小于等于 nn。
tarjan图不一定联通。
题意:如题 |
思路:
Tarjan算法模板题,对于一个点,看是否为割点时,有以下判断方式:
1.叶结点一定不是割点
2.根节点若有两个子树,那么它就是一个割点
3.非根非叶结点若有一个子树dfs时回不到祖先,那么该点为割点
那么只需要Tarjan记录一下dfn和low即可。最后注意一下题给数据不一定使得图联通,要对每个没dfs到的点跑一个 Tarjan。
AC代码:
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 5e5+5;
const int inf=0x3f3f3f3f;
con