SHARE
TWEET

Untitled

a guest Jan 21st, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int m,n,i,p,j,k,c[101][101],d[101][101],pinf=10000,nr;
  5. void citire()
  6. { cin>>n>>m;
  7. int i,j;
  8. for(i=1;i<n;i++)
  9.     for(j=i+1;j<=n;j++)
  10.     c[i][j]=c[j][i]=pinf;
  11. for(k=1;k<=m;k++)
  12.   {cin>>i>>j>>p;
  13.      c[i][j]=p;
  14.   }
  15. }
  16. void roy()
  17. { int i,j,k;
  18.     for(i=1;i<=n;i++)
  19.   {for(j=1;j<=n;j++)
  20.     d[i][j]=c[i][j];
  21.   }
  22.   for(k=1;k<=n;k++)
  23.   {for(i=1;i<=n;i++)
  24.         for(j=1;j<=n;j++)
  25.         if(d[i][j]>d[i][k]+d[k][j])
  26.         d[i][j]=d[i][k]+d[k][j];
  27.   }
  28.  
  29.  
  30. }
  31.  void afisare()
  32.  {
  33.      int i,j;
  34.      for(i=1;i<=n;i++)
  35.         for(j=1;j<=n;j++)
  36.           if(d[i][j]>0&&d[i][j]!=pinf)
  37.             if(c[i][j]>0&&c[i][j]!=pinf)
  38.             if(c[i][j]==d[i][j])
  39.         nr++;
  40.      cout<<nr;
  41.  }
  42.  
  43. int main()
  44. {
  45.     citire();
  46.     roy();
  47.     afisare();
  48.  
  49.     return 0;
  50. }
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