1 #include <iostream> 2 #include <iomanip> 3 4 using namespace std; 5 6 int m, n; 7 int e[10010][10010], t1, t2, t3; 8 9 int main(){ 10 cin >> n >> m; 11 for(int i = 1; i <= n; i ++) 12 for(int j = 1; j <= n; j ++) 13 if(i == j) e[i][j] = 0; 14 else e[i][j] = 99999999; 15 for(int i = 1; i <= m; i ++){ 16 cin >> t1 >> t2 >> t3; 17 e[t1][t2] = t3; 18 } 19 for(int k = 1; k <= n; k ++) 20 for(int i = 1; i <= n; i ++) 21 for(int j = 1; j <= n; j ++) 22 if(e[i][j] > e[i][k] + e[k][j]) 23 e[i][j] = e[i][k] + e[k][j]; 24 for(int i = 1; i <= n; i ++){ 25 for(int j = 1; j <= n; j ++) 26 cout << setw(4) << e[i][j]; 27 cout << endl; 28 } 29 return 0; 30 }