SHARE
TWEET

Untitled

a guest Nov 18th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("intrare.in");
  4. ofstream fout("graf.out");
  5. const int inf=999;
  6. int n,m,A[101][101],dmax=0;
  7.  
  8. void roy()
  9. {
  10.     for(int k=1;k<=n;k++)
  11.         for(int i=1;i<=n;i++)
  12.             for(int j=1;j<=n;j++)
  13.                 if(A[i][j]>A[i][k]+A[k][j])
  14.                     A[i][j]=A[i][k]+A[k][j];
  15. }
  16.  
  17. int main()
  18. {
  19.     fin>>n>>m;
  20.     for(int i=1;i<=n;i++)
  21.         for(int j=1;j<=n;j++)
  22.             if(i!=j) A[i][j]=inf;
  23.     for(int i=1;i<=m;i++)
  24.     {
  25.         int x,y,c;
  26.         fin>>x>>y>>c;
  27.         A[x][y]=c;
  28.     }
  29.     roy();
  30.     for(int i=1;i<=n;i++)
  31.         for(int j=1;j<=n;j++)
  32.             if(A[i][j]>dmax) dmax=A[i][j];
  33.     fout<<dmax<<endl;
  34.     for(int i=1;i<=n;i++)
  35.         for(int j=1;j<=n;j++)
  36.             if(A[i][j]==dmax)
  37.                 fout<<i<<" "<<j<<endl;
  38.     return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top