-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigraph.h
More file actions
34 lines (22 loc) · 877 Bytes
/
Digraph.h
File metadata and controls
34 lines (22 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef DIGRAPH_H
#define DIGRAPH_H
#include <unordered_set>
#include <vector>
class Digraph {
private:
const std::size_t _num_vertices;
std::size_t _num_edges;
std::vector<std::unordered_set<int>> _adjacency_lists;
std::vector<std::size_t> _indegree;
public:
Digraph(std::size_t num_vertices);
inline std::size_t num_vertices() const noexcept { return _num_vertices; }
inline std::size_t num_edges() const noexcept { return _num_edges; }
void add_edge(int v, int w);
inline std::vector<int> adjacent(int v) const { return {_adjacency_lists[v].begin(), _adjacency_lists[v].end()}; }
Digraph reverse() const;
// used in Directed_eulerian_cycle
inline std::size_t outdegree(int v) const { return _adjacency_lists[v].size(); }
inline std::size_t indegree(int v) const { return _indegree[v]; }
};
#endif // DIGRAPH_H