This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_3_A"
#include "../Graph/lowlink.hpp"
#include <iostream>
#include <algorithm>
int main() {
std::cin.tie();
std::ios::sync_with_stdio(false);
int n, m;
std::cin >> n >> m;
Graph<> graph(n);
while (m--) {
int u, v;
std::cin >> u >> v;
graph.span(false, u, v);
}
Lowlink<> ll(graph);
auto& ans = ll.artics;
std::sort(ans.begin(), ans.end());
for (auto v : ans) std::cout << v << "\n";
return 0;
}#line 1 "Verify/articulation_points.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_3_A"
#line 2 "Graph/lowlink.hpp"
#line 2 "Graph/graph.hpp"
#include <vector>
template <class Cost = int>
struct Edge {
int src, dst;
Cost cost;
Edge() = default;
Edge(int src, int dst, Cost cost = 1)
: src(src), dst(dst), cost(cost){};
bool operator<(const Edge<Cost>& e) const { return cost < e.cost; }
bool operator>(const Edge<Cost>& e) const { return cost > e.cost; }
};
template <class Cost = int>
struct Graph : public std::vector<std::vector<Edge<Cost>>> {
using std::vector<std::vector<Edge<Cost>>>::vector;
void span(bool direct, int src, int dst, Cost cost = 1) {
(*this)[src].emplace_back(src, dst, cost);
if (!direct) (*this)[dst].emplace_back(dst, src, cost);
}
};
#line 4 "Graph/lowlink.hpp"
template <class Cost = int>
struct Lowlink {
Graph<Cost> graph;
int time;
std::vector<int> order, low;
std::vector<int> artics;
std::vector<Edge<Cost>> bridges;
explicit Lowlink(const Graph<Cost>& graph)
: graph(graph), order(graph.size(), -1), low(graph.size(), graph.size()) {
time = 0;
for (int v = 0; v < (int)graph.size(); ++v) {
if (order[v] < 0) dfs(v, -1);
}
}
void dfs(int v, int r) {
order[v] = low[v] = time++;
int deg = 0;
bool is_artic = false;
for (auto e : graph[v]) {
if (order[e.dst] < 0) {
++deg;
dfs(e.dst, e.src);
low[e.src] = std::min(low[e.src], low[e.dst]);
if (order[e.src] <= low[e.dst]) is_artic = true;
if (order[e.src] < low[e.dst]) bridges.push_back(e);
} else if (e.dst != r) {
low[e.src] = std::min(low[e.src], order[e.dst]);
}
}
if (r < 0) is_artic = (deg > 1);
if (is_artic) artics.push_back(v);
}
};
#line 4 "Verify/articulation_points.test.cpp"
#include <iostream>
#include <algorithm>
int main() {
std::cin.tie();
std::ios::sync_with_stdio(false);
int n, m;
std::cin >> n >> m;
Graph<> graph(n);
while (m--) {
int u, v;
std::cin >> u >> v;
graph.span(false, u, v);
}
Lowlink<> ll(graph);
auto& ans = ll.artics;
std::sort(ans.begin(), ans.end());
for (auto v : ans) std::cout << v << "\n";
return 0;
}