This documentation is automatically generated by online-judge-tools/verification-helper
#include "Graph/lowlink.hpp"#pragma once
#include "graph.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 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);
}
};