34 lines
629 B
C++
34 lines
629 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(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 |