Advertisement
slowmindead

matricea lungimilor minime orientate

Nov 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. void citire()
  2. { int i,j,x,y;
  3. f>>n>>m;
  4. for(i=1;i<=n;i++)
  5. for(j=1;j<=n;j++)
  6. if(i==j) c[i][j]=0;
  7. else c[i][j]=max;
  8. for(i=1;i<=m;i++)
  9. { f>>x>>y;
  10. c[x][y]=1;
  11. }
  12. }
  13.  
  14. void rf()
  15. { int i,j,k;
  16. for(k=1;k<=n;k++)
  17. for(i=1;i<=n;i++)
  18. for(j=1;j<=n;j++)
  19. if(c[i][j]>c[i][k]+c[k][j])
  20. c[i][j]=c[i][k]+c[k][j];
  21. }
  22.  
  23. void afis()
  24. { int i,j;
  25. for(i=1;i<=n;i++)
  26. { for(j=1;j<=n;j++)
  27. if(c[i][j]==max) g<<"- ";
  28. else g<<c[i][j]<<" ";
  29. g<<endl;
  30. }
  31. }
  32.  
  33. void main()
  34. { citire();
  35. afis();
  36. rf();
  37. g<<endl;
  38. afis();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement