61 lines
1.0 KiB
C++
61 lines
1.0 KiB
C++
#ifndef GRAPH_H_
|
|
#define GRAPH_H_
|
|
|
|
#include <map>
|
|
#include <set>
|
|
#include <vector>
|
|
#include <utility>
|
|
|
|
namespace graph {
|
|
|
|
template<typename V>
|
|
class Graph {
|
|
public:
|
|
Graph() = default;
|
|
|
|
// Add vertex v
|
|
void insert(const V& v);
|
|
|
|
// Add edge between v and u
|
|
void insert(const V& v, const V& u);
|
|
|
|
// Delete vertex v
|
|
void erase(const V& v);
|
|
|
|
// Delete edge between v and u
|
|
void erase(const V& v, const V& u);
|
|
|
|
// Return true if v and u are connected
|
|
bool connected(const V& v, const V& u);
|
|
private:
|
|
std::map<V, std::set<V>> adjacency;
|
|
};
|
|
|
|
template<typename V>
|
|
inline void Graph<V>::insert(const V& v) {
|
|
adjacency[v];
|
|
}
|
|
|
|
template<typename V>
|
|
inline void Graph<V>::insert(const V& v, const V& u) {
|
|
adjacency[v].insert(u);
|
|
}
|
|
|
|
template<typename V>
|
|
inline void Graph<V>::erase(const V& v) {
|
|
adjacency.erase(v);
|
|
}
|
|
|
|
template<typename V>
|
|
inline void Graph<V>::erase(const V& v, const V& u) {
|
|
adjacency[v].erase(u);
|
|
}
|
|
|
|
template<typename V>
|
|
inline bool Graph<V>::connected(const V& v, const V& u) {
|
|
return true;
|
|
}
|
|
|
|
} // namespace graph
|
|
|
|
#endif |