a53

DSLM

a53
Feb 6th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("dslm.in");
  4. ofstream g("dslm.out");
  5.  
  6. int a[21][21],n,p, d[100], dmax[100],lgmax;
  7.  
  8. void citire()
  9. {
  10. int i,x,y;
  11. f>>n>>p;
  12. while(f>>x>>y)
  13. a[x][y]=1;
  14. }
  15. void copie(int lg)
  16. {
  17. lgmax=lg;
  18. for(int i=1; i<=lg; i++) dmax[i]=d[i];
  19. }
  20.  
  21. void scrie_drum()
  22. {
  23. for(int i=1; i<=lgmax; i++)
  24. g<<dmax[i]<<" ";
  25. g<<endl;
  26. }
  27.  
  28. void dfs(int x, int lg)
  29. {
  30. d[lg]=x;
  31. int ex_s=0, y;
  32. for(y=1; y<=n; y++)
  33. if(a[x][y])
  34. {
  35. a[x][y]=0;
  36. ex_s=1;
  37. dfs(y,lg+1);
  38. a[x][y]=1;
  39. }
  40. if(ex_s==0 && lg>lgmax)
  41. copie(lg);
  42. }
  43.  
  44. int main()
  45. {
  46. citire();
  47. dfs(p,1);
  48. scrie_drum();
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment