Add roditty and zwick class
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "graph.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
|
||||
namespace graph {
|
||||
|
||||
@@ -12,10 +13,19 @@ class Digraph : public Graph<T> {
|
||||
public:
|
||||
Digraph() = default;
|
||||
|
||||
Digraph(std::map<T, std::set<T>> digraph);
|
||||
|
||||
// Reverse graph directions
|
||||
Digraph<T> reverse();
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Digraph<T>::Digraph(std::map<T, std::set<T>> digraph) {
|
||||
Graph<T>::adjMatrix = digraph;
|
||||
auto kv = std::views::keys(Graph<T>::adjMatrix);
|
||||
Graph<T>::vertices = std::set<T>{ kv.begin(), kv.end() };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Digraph<T> Digraph<T>::reverse() {
|
||||
return Digraph<T>();
|
||||
|
||||
@@ -12,8 +12,13 @@ class SCC : public Graph<T> {
|
||||
public:
|
||||
SCC(std::map<T, std::set<T>> scc);
|
||||
|
||||
//
|
||||
T representative() { return proxy; };
|
||||
private:
|
||||
T root;
|
||||
// Each SCC has a representative vertex that helps
|
||||
// answer strong connectivity queries in O(1) time
|
||||
T proxy;
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -21,7 +26,7 @@ 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() };
|
||||
root = scc.begin()->first;
|
||||
proxy = scc.begin()->first;
|
||||
}
|
||||
|
||||
}; // namespace graph
|
||||
|
||||
Reference in New Issue
Block a user