Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. ifstream f("graf.txt");
  4. int G[10][10],v[10],n,m,l;
  5. void matrice_adiacenta_vector()
  6. {
  7. f>>n>>m;
  8. int a,b;
  9. for(int i=1;i<=m;i++)
  10. {
  11. f>>a>>b;
  12. G[a][b]=1;
  13. }
  14. f>>l;
  15. for(int i=1;i<=l;i++)
  16. f>>v[i];
  17. }
  18. void afisare_matrice()
  19. {
  20. for(int i=1;i<=n;i++)
  21. {
  22. cout<<endl;
  23. for(int j=1;j<=n;j++)
  24. cout<<G[i][j]<<" ";
  25. }
  26. }
  27. int verf_drum()
  28. {
  29. int OK=1;
  30. for(int i=1;i<l;i++)
  31. if(G[v[i]][v[i+1]] == 0)
  32. OK=0;
  33. if(OK == 1)
  34. {
  35. cout<<endl<<"vectorul este drum";
  36. return 1;
  37. }
  38. else
  39. {
  40. cout<<endl<<"nu este drum";
  41. return 0;
  42. }
  43. }
  44. int elementar()
  45. {
  46. int OK=1;
  47. for(int i=1;i<l;i++)
  48. for(int j=i+1;j<=l;j++)
  49. if(v[i]==v[j])
  50. return 0;
  51. return 1;
  52. }
  53. int simplu()
  54. {
  55. int OK=1;
  56. for(int i=1;i<n;i++)
  57. for(int j=i+1;j<n;j++)
  58. if(G[v[i]][v[i+1]] == G[v[j]][v[j+1]])
  59. OK=0;
  60. if(OK = 1)
  61. return 1;
  62. else
  63. return 0;
  64. }
  65. int main()
  66. {
  67. matrice_adiacenta_vector();
  68. afisare_matrice();
  69. verf_drum();
  70. if(verf_drum)
  71. {
  72. if(elementar())
  73. cout<<endl<<"e drum elementar";
  74. else
  75. cout<<endl<<"nu e drum elementar";
  76. if(simplu())
  77. cout<<endl<<"e drum simplu";
  78. else
  79. cout<<endl<<"nu e drum simplu";
  80. if(v[1] == v[l])
  81. {
  82. cout<<endl<<"drumul este circuit";
  83. if(elementar)
  84. cout<<endl<<"e circuit elementar";
  85. else
  86. cout<<endl<<"nu e circuit elementar";
  87. }
  88. else
  89. cout<<endl<<"drumul nu e circuit";
  90. }
  91. if(elementar())
  92. cout<<endl<<"drumul este hamiltonian";
  93. else
  94. cout<<endl<<"drumul nu este hamiltonian";
  95. if(simplu())
  96. cout<<endl<<"drumul este eulerian";
  97. else
  98. cout<<endl<<"drumul nu este eulerian";
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement