-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11404.cpp
More file actions
44 lines (35 loc) · 862 Bytes
/
11404.cpp
File metadata and controls
44 lines (35 loc) · 862 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
#include <iostream>
#include <vector>
using namespace std;
int arr[111][111];
const int INF = 2100000000;
int main(){
int n, m;
cin>>n>>m;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(i==j) arr[i][j]=0;
else arr[i][j]=INF;
}
}
for(int i=0; i<m; i++){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
arr[a][b]=min(arr[a][b], c);
}
for(int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(arr[i][k]!=INF && arr[k][j]!=INF) arr[i][j] = min(arr[i][j], arr[i][k]+arr[k][j]);
}
}
}
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<<endl;
}
return 0;
}