Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Floyd-Warshall/Floyd-Warshall.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>

using namespace std;

/*
* Algorithm that calculates the distance between all vertices
* of a graph.
*
* Further reading at:
* https://cp-algorithms.com/graph/all-pair-shortest-path-floyd-warshall.html
*/

void floydWarshall( vector< vector < int > > d ){
const int n = v.size();
const int INF = 1e8;
for(int k = 0;k < n;++k){
for(int i = 0;i < n;++i){
for(int j = 0;j < n;++j){
if(d[i][k] < INF && d[k][j] < INF){
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
}