Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<conio.h>
  4. struct nod{int info;nod*leg};
  5. nod *l[50],*p;
  6. int n,a[50][50]={0},x,y;
  7. const int inf=10000;
  8. void citire()
  9. {
  10. ifstream f("graf.txt");
  11. int i,j,c;
  12. f>>n;
  13. for(i=1;i<=n;i++)
  14. for(j=1;j<=n;j++)if(i!=j)a[i][j]=inf;
  15. while(f>>i>>j>>c)
  16. {
  17. a[i][j]=a[j][i]=c;
  18. }
  19. f.close();
  20. }
  21. void afisare()
  22. {
  23. for(int i=1;i<=n;i++)
  24. {
  25. cout<<endl;
  26. for(int j=1;j<=n;j++)cout<<a[i][j]<<" ";
  27. }
  28. }
  29. void drum()
  30. {
  31. for(int k=1;k<=n;k++)
  32. for(int i=1;i<=n;i++)
  33. for(int j=1;j<=n;j++)
  34. if(a[i][j]>a[i][k]+a[k][j])a[i][j]=a[i][k]+a[k][j];
  35. }
  36. void subprogram(int x,int y)
  37. {
  38. bool g=false;
  39. int k=1;
  40. while(k<=n&&!g)
  41. {
  42. if(k!=x&&k!=y)
  43. if(a[x][y]==a[x][k]+a[k][y])
  44. {
  45. g=true;
  46. subprogram(x,k);
  47. subprogram(k,y);
  48. }
  49. }
  50. void scriere(int x,int y)
  51. {
  52. drum();
  53. if(a[x][y]<inf)
  54. {
  55. cout<<"Drumul de la"<<" "<<x<<" "<<"la"<<" "<<y<<" "<<este<<" "<<a[x][y];
  56. cout<<"Nodul de plecare este "<<x;
  57. drum(x,y);
  58. }
  59. else cout<<"Nu este drum ";
  60.  
  61. }
  62. int main()
  63. {
  64. citire();afisare();drum();
  65. cout<<"x=";cin>>x;cout<<endl;
  66. cout<<"y= ";cin>>y;cout<<endl;
  67. subprogram(x,y);
  68. scriere(x,y);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement