forked from maiquynhtruong/algorithms-and-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva821-page-hopping.cpp
44 lines (43 loc) · 904 Bytes
/
uva821-page-hopping.cpp
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
44
#include <bits/stdc++.h>
using namespace std;
int V = 100;
void floyd_warshall() {
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
adjMat[i][j] = min(adjMat[i][j], adjMat[i][k] + adjMat[k][j]);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
while (cin >> a >> b) {
if (a == 0 && b == 0) break;
int adjMat[105][105];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
adjMat[i][j] = INF;
}
}
adjMat[a][b] = 1;
while (cin >> a >> b) {
if (a == 0 && b == 0) break;
adjMat[a][b] = 1;
}
floyd_warshall();
double average = 0.0;
int connections = 0;
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (i != j && adjMat[i][j] != INF) {
connections++;
average += adjMat[i][j];
}
}
}
cout << average / connections << "\n";
}
return 0;
}