Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define mx 10000
  4. int cost[mx][mx],adj[mx][mx],dis[mx],n,e,i,j,c,k;
  5. void floyed()
  6. {
  7.     for(k=0;k<n;k++){
  8.         for(i=0;i<n;i++){
  9.             for(j=0;j<n;j++){
  10.                 if(cost[i][j]>cost[i][k]+cost[k][j]){
  11.                     cost[i][j]=cost[i][k]+cost[k][j];
  12.                 }
  13.             }
  14.         }
  15.     }
  16. }
  17. int main()
  18. {
  19.     cin>>n>>e;
  20.     for(i=0;i<n;i++){
  21.         for(j=0;j<n;j++){
  22.             if(i==j){
  23.                 cost[i][j]=0;
  24.             }
  25.             else cost[i][j]=100000;
  26.         }
  27.     }
  28.     for(i=0;i<e;i++){
  29.         int n1,n2;
  30.         cin>>n1>>n2>>c;
  31.         cost[n1][n2]=c;
  32.         cost[n2][n1]=c;
  33.     }
  34.     floyed();
  35.     for(i=0;i<n;i++){
  36.         for(j=0;j<n;j++){
  37.             cout<<cost[i][j]<<" ";
  38.         }
  39.         cout<<endl;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement