Advertisement
hegemon88676

roy-floyd

Feb 23rd, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. ///ROY-FLOYD
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5. int cost[100][100], n;
  6. void citire()
  7. {
  8.     ifstream f("graf.in");
  9.     f>>n;
  10.     for (int i=1; i<=n; ++i)
  11.         for(int j=1; j<=n; j++)
  12.             f>>cost[i][j];
  13. }
  14. int main()
  15. {
  16.     citire();
  17.     int i,j,k;
  18.     for(k=1; k<=n; k++)
  19.         for (int i=1; i<=n; ++i)
  20.             for(int j=1; j<=n; j++)
  21.                 if(i!=j && i!=k && k!=j && cost[i][k]!=-1 && cost[k][j]!=-1 && cost[i][j]>cost[i][k]+cost[k][j])
  22.                     cost[i][j]=cost[i][k]+cost[k][j];
  23.     for (int i=1; i<=n; ++i)
  24.     {
  25.         for(int j=1; j<=n; j++)
  26.             cout<<cost[i][j]<<" ";
  27.         cout<<endl;
  28.     }
  29. }
  30. /*graf.in
  31. 5
  32. -1 -1 100 10 50
  33. -1 -1 -1 10 -1
  34. 100 -1 -1 -1 10
  35. 10 10 -1 -1 10
  36. 50 -1 10 10 -1
  37. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement