-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathN11404.cpp
36 lines (32 loc) · 812 Bytes
/
N11404.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
# include<stdio.h>
# include<vector>
# include<queue>
# include<algorithm>
# include <limits.h>
using namespace std;
int getMinCost(int,int,int);
vector<vector<long long> > cost;
int n,m;
int main(){
int i,j;
long long val;
scanf("%d",&n);
scanf("%d",&m);
cost.assign(n+1,vector<long long>(n+1,INT_MAX));
for(int k = 1;k<=m;k++){
scanf("%d %d %lld",&i,&j,&val);
cost[i][j] = min(cost[i][j],val);
}
for(int i = 1; i<=n;i++)
cost[i][i] = 0;
for (int k = 1;k<=n;k++)
for (int i = 1;i<=n;i++)
for (int j = 1;j<=n;j++)
cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
for(int i = 1 ;i<=n;i++){
for(int j = 1 ;j<=n;j++){
printf("%lld ",cost[i][j]);
}
printf("\n");
}
}