You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now, let's use Dijkstra's Shortest Paths algorithm to determine the distance from vertex `0` to each vertex in `g`, and also to determine these paths. The paths are not obtained directly, but instead the list of predecessors is returned for each vertex:
23
+
24
+
```c++
25
+
auto weight = [](std::tuple<int, double> const& uv) {
26
+
return std::get<1>(uv);
27
+
};
28
+
29
+
std::vector<double> distances(g.size()); // we will store the distance to each vertex here
30
+
std::vector<int> predecessors(g.size()); // we will store the predecessor of each vertex here
31
+
32
+
// fill `distances` with `infinity`
33
+
// fill `predecessors` at index `i` with value `i`
Now, let's use Dijkstra's Shortest Paths algorithm to determine the distance from vertex `0` to each vertex in `g`, and also to determine these paths. The paths are not obtained directly, but instead the list of predecessors is returned for each vertex:
146
-
147
-
```c++
148
-
auto weight = [](std::tuple<int, double> const& uv) {
149
-
return std::get<1>(uv);
150
-
};
151
-
152
-
std::vector<double> distances(g.size()); // we will store the distance to each vertex here
153
-
std::vector<int> predecessors(g.size()); // we will store the predecessor of each vertex here
154
-
155
-
// fill `distances` with `infinity`
156
-
// fill `predecessors` at index `i` with value `i`
0 commit comments