Advertisement
a53

drumuri_simple_k

a53
Jun 12th, 2020
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int x,y,k,v[12],n,m,ok,a[21][21];
  4.  
  5. void afis()
  6. {
  7. for(int i=1;i<=k;++i)
  8. cout<<v[i]<<' ';
  9. cout<<'\n';
  10. ok=1;
  11. }
  12.  
  13. int verif(int p)
  14. {
  15. if(p>1&&a[v[p-1]][v[p]]!=1)
  16. return 0;
  17. return 1;
  18. }
  19.  
  20. void bt(int x)
  21. {
  22. if(x==k+1)
  23. afis();
  24. else
  25. for(int i=1;i<=n;++i)
  26. {
  27. v[x]=i;
  28. if(verif(x))
  29. if(x>1)
  30. a[v[x-1]][v[x]]=2,bt(x+1),a[v[x-1]][v[x]]=1;
  31. else
  32. bt(x+1);
  33. }
  34. }
  35.  
  36. int main()
  37. {
  38. cin>>n>>m>>k;k++;
  39. for(int i=1;i<=m;++i)
  40. cin>>x>>y,a[x][y]=1;
  41. bt(1);
  42. if(!ok)
  43. cout<<"Nu exista";
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement