Advertisement
a53

LantZ

a53
May 15th, 2022
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("lantz.in");
  4. ofstream fout("lantz.out");
  5. int n, m, A[105][105], x[105],l, ok;
  6.  
  7. void afisare(int k)
  8. {
  9. ok=1;
  10. for(int i=1; i<=k; ++ i)
  11. fout<<x[i]<<" ";
  12. fout<<'\n';
  13. }
  14.  
  15. int OK(int k)
  16. {
  17. if(k>1)
  18. if(A[x[k-1]][x[k]] != 1)
  19. return 0;
  20. for(int i=1; i<k ; ++i)
  21. if(x[k]==x[i])
  22. return 0;
  23. return 1;
  24. }
  25.  
  26. bool verifica(int k)
  27. {
  28. return (k==l+1);
  29. }
  30.  
  31. void Back(int k)
  32. {
  33. for(int i=1; i<=n; ++i)
  34. {
  35. x[k]=i;
  36. if(OK(k))
  37. {
  38. if(verifica(k))
  39. afisare(k);
  40. else
  41. Back(k + 1);
  42. }
  43. }
  44. }
  45. int main()
  46. {
  47. fin>>n>>m;
  48. int a, b;
  49. for(int i=1; i<=m; ++i)
  50. {
  51. fin>>a>>b;
  52. A[a][b]=A[b][a]=1;
  53. }
  54. fin>>l;
  55. Back(1);
  56. if(!ok)
  57. fout<<"NU EXISTA";
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement