Files
reachability-algorithms/graph/scc.h
2022-06-27 17:45:47 +03:00

36 lines
649 B
C++

#ifndef SCC_H_
#define SCC_H_
#include "graph.h"
#include <ranges>
namespace graph {
template<typename T>
class SCC : public Graph<T> {
public:
SCC() = default;
SCC(std::map<T, std::set<T>> scc);
//
T representative() { return proxy; };
private:
// Each SCC has a representative vertex that helps
// answer strong connectivity queries in O(1) time
T proxy;
};
template<typename T>
SCC<T>::SCC(std::map<T, std::set<T>> scc) {
Graph<T>::adjMatrix = scc;
auto kv = std::views::keys(Graph<T>::adjMatrix);
Graph<T>::vertices = std::set<T>{ kv.begin(), kv.end() };
proxy = scc.begin()->first;
}
}; // namespace graph
#endif