Guest User

Untitled

a guest
Dec 3rd, 2019
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. ifstream f("ciclu.in");
  8. ofstream g("ciclu.out");
  9.  
  10. int a[21][21],use[21],n,r,m,k,q,p,v[101];
  11.  
  12.  
  13.  
  14. void afis(int k)
  15. {
  16.  
  17. if(use[p]==1)
  18. {
  19.  
  20.  
  21. for(int i=1;i<=k;i++)
  22. g<<v[i]<<' ';
  23. exit(EXIT_SUCCESS);
  24. }
  25.  
  26.  
  27. return;
  28. }
  29.  
  30.  
  31. void bkt(int x, int k)
  32. {
  33. for(int i=1;i<=n;i++)
  34. {
  35. if(a[x][i] && !use[i])
  36. {
  37. v[k]=i;
  38. use[i]=1;
  39. if(i==p && k>3)
  40. afis(k);
  41. else
  42. bkt(i,k+1);
  43. use[i]=0;
  44. }
  45. }
  46. }
  47.  
  48.  
  49.  
  50. int main()
  51. {
  52. f>>n>>m;
  53. int x,y,i;
  54. for(i=1;i<=m;i++)
  55. {
  56. f>>x>>y;
  57. a[x][y]=a[y][x]=1;
  58. }
  59.  
  60. f>>p;
  61. v[1]=p;
  62.  
  63. bkt(p,2);
  64. return 0;
  65. }
RAW Paste Data