Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #define INF 1000000
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int n,m,c[101][101],a[101][101];
  6.  
  7.  
  8. void citire()
  9. {
  10. int x,y,cost;
  11. cin>>n>>m;
  12. for(int i=1;i<=m;i++)
  13. {
  14. cin>>x>>y>>cost;
  15. c[x][y]=cost;
  16. a[x][y]=cost;
  17.  
  18. }
  19. }
  20.  
  21.  
  22. void matrice()
  23. {
  24. for(int i=1;i<=n;i++)
  25. for(int j=1;j<=n;j++)
  26. if(i!=j && c[i][j]==0)
  27. c[i][j]=a[i][j]=INF;
  28. }
  29.  
  30.  
  31. void RoyFloyd()
  32. {
  33. for(int k=1;k<=n;k++)
  34. for(int i=1;i<=n;i++)
  35. for(int j=1;j<=n;j++)
  36. if(c[i][j]>c[i][k]+c[k][j])
  37. c[i][j]=c[i][k]+c[k][j];
  38.  
  39. }
  40. int main()
  41. {
  42. citire();
  43. matrice();
  44. RoyFloyd();
  45. int nr=0;
  46. for(int i=1;i<=n;i++)
  47. for(int j=1;j<=n;j++)
  48. if(c[i][j]==a[i][j] && c[i][j]>0 && c[i][j]<INF)
  49. nr++;
  50. cout<<nr;
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement