Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. ifstream f("graf.in");
  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. if(simplu())
  88. cout<<endl<<"e circuit simplu";
  89. else
  90. cout<<endl<<"nu e circuit simplu";
  91. }
  92. else
  93. cout<<endl<<"drumul nu e circuit";
  94. }
  95. if(elementar())
  96. cout<<endl<<"drumul este hamiltonian";
  97. else
  98. cout<<endl<<"drumul nu este hamiltonian";
  99. if(simplu())
  100. cout<<endl<<"drumul este eulerian";
  101. else
  102. cout<<endl<<"drumul nu este eulerian";
  103.  
  104. }
  105. #include<bits/stdc++.h>
  106. using namespace std;
  107. ifstream f("graf.in");
  108. int G[10][10],v[10],n,m,l;
  109. void matrice_adiacenta_vector()
  110. {
  111. f>>n>>m;
  112. int a,b;
  113. for(int i=1;i<=m;i++)
  114. {
  115. f>>a>>b;
  116. G[a][b]=1;
  117. }
  118. f>>l;
  119. for(int i=1;i<=l;i++)
  120. f>>v[i];
  121. }
  122. void afisare_matrice()
  123. {
  124. for(int i=1;i<=n;i++)
  125. {
  126. cout<<endl;
  127. for(int j=1;j<=n;j++)
  128. cout<<G[i][j]<<" ";
  129. }
  130. }
  131. int verf_drum()
  132. {
  133. int OK=1;
  134. for(int i=1;i<l;i++)
  135. if(G[v[i]][v[i+1]] == 0)
  136. OK=0;
  137. if(OK == 1)
  138. {
  139. cout<<endl<<"vectorul este drum";
  140. return 1;
  141. }
  142. else
  143. {
  144. cout<<endl<<"nu este drum";
  145. return 0;
  146. }
  147. }
  148. int elementar()
  149. {
  150. int OK=1;
  151. for(int i=1;i<l;i++)
  152. for(int j=i+1;j<=l;j++)
  153. if(v[i]==v[j])
  154. return 0;
  155. return 1;
  156. }
  157. int simplu()
  158. {
  159. int OK=1;
  160. for(int i=1;i<n;i++)
  161. for(int j=i+1;j<n;j++)
  162. if(G[v[i]][v[i+1]] == G[v[j]][v[j+1]])
  163. OK=0;
  164. if(OK = 1)
  165. return 1;
  166. else
  167. return 0;
  168. }
  169. int main()
  170. {
  171. matrice_adiacenta_vector();
  172. afisare_matrice();
  173. verf_drum();
  174. if(verf_drum)
  175. {
  176. if(elementar())
  177. cout<<endl<<"e drum elementar";
  178. else
  179. cout<<endl<<"nu e drum elementar";
  180. if(simplu())
  181. cout<<endl<<"e drum simplu";
  182. else
  183. cout<<endl<<"nu e drum simplu";
  184. if(v[1] == v[l])
  185. {
  186. cout<<endl<<"drumul este circuit";
  187. if(elementar)
  188. cout<<endl<<"e circuit elementar";
  189. else
  190. cout<<endl<<"nu e circuit elementar";
  191. if(simplu())
  192. cout<<endl<<"e circuit simplu";
  193. else
  194. cout<<endl<<"nu e circuit simplu";
  195. }
  196. else
  197. cout<<endl<<"drumul nu e circuit";
  198. }
  199. if(elementar())
  200. cout<<endl<<"drumul este hamiltonian";
  201. else
  202. cout<<endl<<"drumul nu este hamiltonian";
  203. if(simplu())
  204. cout<<endl<<"drumul este eulerian";
  205. else
  206. cout<<endl<<"drumul nu este eulerian";
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement