#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cassert>
#include <map>
|
template<typename Assoc_Cont > |
Assoc_Cont & | floyds_sp (WeightedGraph &G) |
|
int | main () |
|
template<typename Assoc_Cont >
Assoc_Cont& floyds_sp |
( |
WeightedGraph & |
G | ) |
|
15 Assoc_Cont& path_wt = *(
new Assoc_Cont);
17 int V = G.no_of_vertices();
20 for(
int i = 0; i < V; i++) {
21 for(
int j = 0; j < V; j++) {
24 else if(G.weight(i, j) != -1)
25 path_wt[i][j] = G.weight(i, j);
31 vector<int> vertex_set(V);
32 G.get_vertices(vertex_set.begin());
34 for(
int pivot : vertex_set) {
37 for(
int from : vertex_set)
38 for(
int to : vertex_set)
39 if(path_wt[from][to] > path_wt[from][pivot] + path_wt[pivot][to])
40 path_wt[from][to] = path_wt[from][pivot] + path_wt[pivot][to];
56 map<int, map<int, int>> path_wt;
58 path_wt = floyds_sp<map<int, map<int, int>>>(G);
60 for(
int i = 0; i < 4; i++) {
61 for(
int j = 0; j < 4; j++)
62 cout << path_wt[i][j] <<
"\t";