Advertisement
Mattia-Iojica

Cost maxim

Apr 3rd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #define inf 10000
  4. using namespace std;
  5.  
  6. ifstream fin("graf.in");
  7. ofstream fout("graf.out");
  8.  
  9. int n,m,A[101][101],nr=0;
  10.  
  11. void Roy()
  12. {
  13.     for(int k=1;k<=n;k++)
  14.         for(int i=1;i<=n;i++)
  15.             for(int j=1;j<=n;j++)
  16.                 if(A[i][j]>A[i][k]+A[k][j])
  17.                    {
  18.                     cout<<"A["<<i<<","<<j<<"]="<<A[i][j]<<" ia valoarea "<<"A["<<i<<","<<k<<"]="<<A[i][k]<< " + "<<"A["<<k<<","<<j<<"]="<<A[k][j]<<"   ="  ;
  19.                     A[i][j]=A[i][k]+A[k][j];
  20.                     cout<<A[i][j]<<endl;
  21.                     }
  22.  
  23. }
  24.  
  25. int main()
  26. {
  27.     int x,y,c;
  28.     fin>>n>>m;
  29.     for(int i=1;i<=n;i++)
  30.         for(int j=1;j<=n;j++)
  31.             if(i!=j)
  32.                 A[i][j]=inf;
  33.     for(int i=1;i<=m;i++)
  34.     {
  35.         fin>>x>>y>>c;
  36.         A[x][y]=c;
  37.     }
  38.     Roy();
  39.     for(int i=1;i<=n;i++)
  40.         for(int j=1;j<=n;j++)
  41.             if(A[i][j]>nr)
  42.             nr=A[i][j];
  43.     fout<<nr<<endl;
  44.     for(int i=1;i<=n;i++)
  45.         for(int j=1;j<=n;j++)
  46.             if(A[i][j]==nr)
  47.                 fout<<i<<" "<<j<<endl;
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement