This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/GRL_3_A"
#include "graph/articulation_points.hpp"
#include <bits/stdc++.h>
int main() {
std::cin.tie(0)->sync_with_stdio(0);
int n, m;
std::cin >> n >> m;
std::vector<std::vector<int>> g(n);
for (auto i = 0; i < m; ++i) {
int u, v;
std::cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
auto cutpoints = find_cutpoints(g);
std::ranges::sort(cutpoints);
std::ranges::copy(cutpoints, std::ostream_iterator<int>(std::cout, "\n"));
}#line 1 "test/graph/articulation_points.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/GRL_3_A"
#line 1 "graph/articulation_points.hpp"
#include <algorithm>
#include <vector>
std::vector<int> find_cutpoints(const auto &g) {
auto n = (int)g.size();
auto timer = 0;
std::vector<int> visited(n), tin(n, -1), low(n, -1);
std::vector<int> cutpoints;
auto dfs = [&](auto self, int u, int p) -> void {
visited[u] = true;
tin[u] = low[u] = timer++;
auto children = 0;
auto is_cutpoint = false;
for (auto v : g[u]) {
if (v == p) {
continue;
}
if (visited[v]) {
low[u] = std::min(low[u], tin[v]);
} else {
self(self, v, u);
low[u] = std::min(low[u], low[v]);
is_cutpoint |= (tin[u] <= low[v] && p != -1);
++children;
}
}
is_cutpoint |= (p == -1 && 1 < children);
if (is_cutpoint) {
cutpoints.push_back(u);
}
};
for (auto i = 0; i < n; ++i) {
if (!visited[i]) {
dfs(dfs, i, -1);
}
}
return cutpoints;
}
#line 4 "test/graph/articulation_points.test.cpp"
#include <bits/stdc++.h>
int main() {
std::cin.tie(0)->sync_with_stdio(0);
int n, m;
std::cin >> n >> m;
std::vector<std::vector<int>> g(n);
for (auto i = 0; i < m; ++i) {
int u, v;
std::cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
auto cutpoints = find_cutpoints(g);
std::ranges::sort(cutpoints);
std::ranges::copy(cutpoints, std::ostream_iterator<int>(std::cout, "\n"));
}