-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadjacencymatrix.cpp
More file actions
43 lines (38 loc) · 918 Bytes
/
adjacencymatrix.cpp
File metadata and controls
43 lines (38 loc) · 918 Bytes
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
void floyd(int **, int);
class AdjMatrix {
private:
void operator = (const AdjMatrix &)
{}
public:
int **g;
int n;
AgjMatrix(int _n) {
n = _n;
g = new int*[n];
for (int i = 0; i < n; i++)
g[i] = new int[n];
}
~AdjMatrix() {
for (int i = 0; i < n; i++)
delete[] g[i];
delete[] g;
}
void floyd()
/**
* if you want to save original weights, you should copy the graph
*/
{
floyd(g, n);
}
};
void floyd(int **g, int n)
/**
* g - adjacency matrix, n - vertex count
* each edge of type 'i to i' has 0-weight
*/
{
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}