Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. int a[101][101],l[101],n,m,k;
  5. ifstream f("24.in");
  6. void citire()
  7. {
  8. f>>n>>m;
  9. int x,y;
  10. for(int i=1;i<=m;i++)
  11. {
  12. f>>x>>y;
  13. a[x][y]=1;
  14. a[y][x]=1;
  15. }
  16. f>>k;
  17. for(int i=1;i<=k;i++)
  18. f>>l[i];
  19. }
  20. int verif_l_hamiltonian()
  21. {
  22. if(k!=n+1)return 0;
  23. if(l[1]!=l[k])return 0;
  24. for(int i=1;i<=k-2;i++)
  25. for(int j=i+1;j<=k-1;j++)
  26. if(l[i]==l[j])return 0;
  27.  
  28. for(int i=1;i<k;i++)
  29. if(a[l[i]][l[i+1]]!=1)return 0;
  30. return 1;
  31. }
  32. int verif_l_eulerian()
  33. {
  34. int i,j;
  35. if(k!=m+1)return 0;
  36. if(l[1]!=l[k])return 0;
  37. for(i=1;i<=k-1;i++)
  38. if(a[l[i]][l[i+1]]==0) return 0;
  39. for(i=1;i<=k-2;i++)
  40. for(j=i+1;j<k-1;j++)
  41. if((l[i]==l[j]&&l[i+1]==l[j+1])||(l[i]==l[j+1]&&l[i+1]==l[j]))
  42. return 0;
  43. return 1;
  44. }
  45. int main()
  46. {
  47. citire();
  48. if(verif_l_hamiltonian()==1)cout<<"Sirul poate reprezenta un ciclu hamiltonian"<<endl;
  49. else cout<<"Sirul nu poate reprezenta un ciclu hamiltonian"<<endl;
  50. if(verif_l_eulerian()==1)cout<<"Sirul poate reprezenta un ciclu eulerian"<<endl;
  51. else cout<<"Sirul nu poate reprezenta un ciclu eulerian"<<endl;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement