forked from Amisha-here/Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloyd.cpp
More file actions
23 lines (22 loc) · 773 Bytes
/
floyd.cpp
File metadata and controls
23 lines (22 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Floyd Warshall algorithm class
class Floyd {
int N;
vector<vector<int> > E;
public:
Floyd(int n) {
N = n;
E = vector<vector<int> >(N + 1, vector<int>(N + 1, INF));
}
void setRC(int r, int c, int w) {
E[r][c] = w;
}
int getRC(int r, int c) {
return E[r][c];
}
void execute() {
int i, j, k;
for (i = 1; i <= N; ++i) E[i][i] = 0;
for (k = 1; k <= N; ++k) for (i = 1; i <= N; ++i) for (j = 1; j <= N; ++j)
E[i][j] = min(E[i][j], E[i][k] + E[k][j]);
}
};