-
Notifications
You must be signed in to change notification settings - Fork 0
/
11403.cpp
49 lines (42 loc) · 992 Bytes
/
11403.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
45
46
47
48
49
#include <iostream>
#include <queue>
#include <algorithm>
#include <limits>
using namespace std;
int main() {
cin.tie(0);
std::ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<vector<int>> v(n, vector<int>(n));
for (auto &i: v) {
for (auto &j: i) {
cin >> j;
}
}
const int limit = numeric_limits<int>::max() / 2;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(v[i][j] == 0){
v[i][j] = limit;
}
}
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (v[i][j] > v[i][k] + v[k][j]) {
v[i][j] = v[i][k] + v[k][j];
}
}
}
}
for (auto &i: v) {
for (auto &j: i) {
if(j == limit) cout << 0;
else cout << 1;
cout << " ";
}
cout << "\n";
}
}