14 this->
edges_[from][to] = cost;
27 if (this->
edges_.count(from) == 0 || this->edges_.at(from).count(to) == 0) {
30 this->
edges_.at(from).erase(to);
38 return this->
edges_.size();
42 return std::accumulate(this->
edges_.begin(), this->edges_.end(), 0,
43 [](
int sum,
const auto& e) {return sum + e.second.size();});
51 if (this->
edges_.count(s) == 0) {
54 std::vector<size_t> connections;
55 for (
auto&& i : this->
edges_.at(s)) {
56 connections.emplace_back(i.first);
62 if (this->
edges_.count(from) == 0 || this->edges_.at(from).count(to) == 0) {
65 return this->
edges_.at(from).at(to);
69 size_t from,
size_t to)
const {
70 std::vector<bool> visited(this->
numNodes(),
false);
71 std::vector<std::vector<size_t>> routes(1);
73 this->
DFS(from, to, routes, visited, route_index);
74 routes.erase(std::remove_if(routes.begin(), routes.end(),
75 [&to] (
const std::vector<size_t> x) {
76 return (x.size() < 1 || x.back() != to);
82 size_t from,
size_t to,
83 std::vector<std::vector<size_t>>& routes,
84 std::vector<bool>& visited,
85 int& route_index)
const {
86 routes.emplace_back(routes[route_index]);
87 routes.back().emplace_back(from);
88 int i_route = routes.size() - 1;
93 this->
DFS(i, to, routes, visited, i_route);
96 visited[from] =
false;
100 std::vector<std::vector<pair_vec_size__int>>
103 std::vector<std::vector<int64_t>> dist(N, std::vector<int64_t>(N, INF));
104 std::vector<std::vector<int64_t>> next(N, std::vector<int64_t>(N, -1));
108 for (
const auto& src : this->
edges_) {
109 for (
const auto& dest : src.second) {
110 dist[src.first][dest.first] = dest.second;
111 next[src.first][dest.first] = dest.first;
113 dist[src.first][src.first] = 0;
118 for (
size_t k = 0; k < N; ++k) {
119 for (
size_t i = 0; i < N; ++i) {
120 for (
size_t j = 0; j < N; ++j) {
121 if (dist[i][k] < INF && \
122 dist[k][j] < INF && \
123 dist[i][j] > dist[i][k] + dist[k][j]) {
124 dist[i][j] = dist[i][k] + dist[k][j];
125 next[i][j] = next[i][k];
133 std::vector<std::vector<pair_vec_size__int>>
134 paths(N, std::vector<pair_vec_size__int>(N));
135 for (
size_t i = 0; i < N; ++i) {
136 for (
size_t j = 0; j < N; ++j) {
137 if (i != j && next[i][j] != -1) {
138 std::vector<size_t>
path = {i};
140 while (current != j) {
141 current = next[current][j];
142 path.push_back(current);
144 paths[i][j] = std::make_pair(
path, dist[i][j]);
145 }
else if (i != j && next[i][j] == -1) {
146 paths[i][j].second = INF;