Skip to content
Snippets Groups Projects
Commit ed7928cd authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Add floyd warshall

parent d70d38f6
No related branches found
No related tags found
No related merge requests found
/**
* Floyd Warshall Algorithm
*
* Complexity (Time): O(n^3)
* Complexity (Space): O(n^2)
*/
int dist[MAX][MAX];
int graph[MAX][MAX];
// Build dist matrix
int floyd_warshall(int n) {
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
dist[i][j] = graph[i][j];
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (dist[i][k] + dist[k][j] < dist[i][j])
dist[i][j] = dist[i][k] + dist[k][j];
}
...@@ -17,6 +17,7 @@ bool cmp(iii a, iii b) { ...@@ -17,6 +17,7 @@ bool cmp(iii a, iii b) {
//* return a.se > b.se //* return a.se > b.se
} }
// Return value of MST and build mst vector with edges that belong to the tree
int kruskal() { int kruskal() {
sort(edges.begin(), edges.end(), cmp); sort(edges.begin(), edges.end(), cmp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment