-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon11404.cpp
More file actions
45 lines (38 loc) · 789 Bytes
/
baekjoon11404.cpp
File metadata and controls
45 lines (38 loc) · 789 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
44
45
#include <iostream>
#define INF 987654321
using namespace std;
int n, m, arr[101][101], from, to, cost;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
arr[i][j] = INF;
}
}
for (int i = 0; i < m; i++) {
cin >> from >> to >> cost;
if(arr[from][to] > cost)
arr[from][to] = cost;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
if (j == k)
continue;
if (arr[j][k] > arr[j][i] + arr[i][k])
arr[j][k] = arr[j][i] + arr[i][k];
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (arr[i][j] == INF)
cout << 0 << " ";
else
cout << arr[i][j] << " ";
}
cout << "\n";
}
}