-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain_SP.cpp.in
58 lines (54 loc) · 1.91 KB
/
main_SP.cpp.in
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/******************************************************************************
* % ./DijkstraSP tinyEWD.txt 0
* 0 to 0 (0.00):
* 0 to 1 (1.05): 0->4 0.38 4->5 0.35 5->1 0.32
* 0 to 2 (0.26): 0->2 0.26
* 0 to 3 (0.99): 0->2 0.26 2->7 0.34 7->3 0.39
* 0 to 4 (0.38): 0->4 0.38
* 0 to 5 (0.73): 0->4 0.38 4->5 0.35
* 0 to 6 (1.51): 0->2 0.26 2->7 0.34 7->3 0.39 3->6 0.52
* 0 to 7 (0.60): 0->2 0.26 2->7 0.34
*
* % ./AcyclicSP tinyEWDAG.txt 5
* 5 to 0 (0.73): 5->4 0.35 4->0 0.38
* 5 to 1 (0.32): 5->1 0.32
* 5 to 2 (0.62): 5->7 0.28 7->2 0.34
* 5 to 3 (0.61): 5->1 0.32 1->3 0.29
* 5 to 4 (0.35): 5->4 0.35
* 5 to 5 (0.00):
* 5 to 6 (1.13): 5->1 0.32 1->3 0.29 3->6 0.52
* 5 to 7 (0.28): 5->7 0.28
*
* % ./BellmanFordSP tinyEWDn.txt 0
* 0 to 0 (0.00):
* 0 to 1 (0.93): 0->2 0.26 2->7 0.34 7->3 0.39 3->6 0.52 6->4 -1.25 4->5 0.35 5->1 0.32
* 0 to 2 (0.26): 0->2 0.26
* 0 to 3 (0.99): 0->2 0.26 2->7 0.34 7->3 0.39
* 0 to 4 (0.26): 0->2 0.26 2->7 0.34 7->3 0.39 3->6 0.52 6->4 -1.25
* 0 to 5 (0.61): 0->2 0.26 2->7 0.34 7->3 0.39 3->6 0.52 6->4 -1.25 4->5 0.35
* 0 to 6 (1.51): 0->2 0.26 2->7 0.34 7->3 0.39 3->6 0.52
* 0 to 7 (0.60): 0->2 0.26 2->7 0.34
*
******************************************************************************/
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include "@[email protected]"
int main(int argc, char *argv[]) {
std::ifstream in(argv[1]);
EdgeWeightedDigraph G(in);
int s = std::stoi(argv[2]);
@SP@ sp(G, s);
for (int t = 0; t < G.V(); ++t) {
std::cout << s << " to " << t;
std::cout << " (" << std::fixed << std::setprecision(2) << std::setw(4) << sp.distTo(t) << "): ";
if (sp.hasPathTo(t)) {
for (const auto &e: sp.pathTo(t)) {
std::cout << e << " ";
}
}
std::cout << std::endl;
}
return 0;
}