@@ -10,25 +10,26 @@ namespace cp_algo::graph {
10
10
template <type _undirected, edge_type edge_t = edge_base>
11
11
struct graph {
12
12
static constexpr bool undirected = _undirected;
13
- graph (int n, int v0 = 0 ): v0(v0), _adj (n) {}
13
+ graph (int n, int v0 = 0 ): v0(v0), adj (n) {}
14
14
15
15
void add_edge (node_index u, edge_t e) {
16
- _adj .push (u, size (edges));
16
+ adj .push (u, size (edges));
17
17
edges.push_back (e);
18
18
if constexpr (undirected) {
19
- _adj .push (e.to , size (edges));
19
+ adj .push (e.to , size (edges));
20
20
}
21
21
edges.push_back (e.backedge (u));
22
22
}
23
23
void read_edges (node_index m) {
24
+ adj.reserve (m);
24
25
for (edge_index i = 0 ; i < m; i++) {
25
26
auto [u, e] = edge_t::read (v0);
26
27
add_edge (u, e);
27
28
}
28
29
}
29
30
void call_adjacent (node_index v, auto &&callback, auto &&terminate) const {
30
- for (int sv = _adj .head [v]; sv && !terminate (); sv = _adj .next [sv]) {
31
- callback (_adj .data [sv]);
31
+ for (int sv = adj .head [v]; sv && !terminate (); sv = adj .next [sv]) {
32
+ callback (adj .data [sv]);
32
33
}
33
34
}
34
35
void call_adjacent (node_index v, auto &&callback) const {
@@ -48,14 +49,14 @@ namespace cp_algo::graph {
48
49
[](edge_index e) {return !(e % 2 );}
49
50
);
50
51
}
51
- auto const & incidence_lists () const {return _adj ;}
52
+ auto const & incidence_lists () const {return adj ;}
52
53
edge_t const & edge (edge_index e) const {return edges[e];}
53
- node_index n () const {return _adj .size ();}
54
+ node_index n () const {return adj .size ();}
54
55
edge_index m () const {return size (edges) / 2 ;}
55
56
private:
56
57
node_index v0;
57
58
std::vector<edge_t > edges;
58
- data_structures::stack_union<edge_index> _adj ;
59
+ data_structures::stack_union<edge_index> adj ;
59
60
};
60
61
}
61
62
#endif // CP_ALGO_GRAPH_BASE_HPP
0 commit comments