Advertisement
Guest User

Lk

a guest
Feb 24th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define Dmax 21
  4. using namespace std;
  5.  
  6. ifstream fin("lanturi1.in");
  7. ofstream fout("lanturi1.out");
  8.  
  9. int n, m, p, q, r, X[Dmax];
  10. bool used[Dmax];
  11.  
  12. inline void print(int k)
  13. {
  14. for (int i = 1; i <= k; ++i)
  15. fout << X[i] << " ";
  16.  
  17. fout << '\n';
  18. }
  19.  
  20. inline bool R_occurence(int k)
  21. {
  22. for (int i = 1; i <= k; ++i)
  23. if (X[i] == r)
  24. return true;
  25.  
  26. return false;
  27. }
  28.  
  29. inline void DFS_Traversal(vector <set <int> > G, int k, int src)
  30. {
  31. for (auto u : G[src])
  32. {
  33. if (!used[u])
  34. {
  35. used[u] = true;
  36. X[k] = u;
  37. if (u == q)
  38. {
  39. if (!R_occurence(k))
  40. print(k);
  41. }
  42. else
  43. DFS_Traversal(G, k + 1, u);
  44.  
  45. used[u] = false;
  46. }
  47. }
  48. }
  49.  
  50. int main()
  51. {
  52. fin >> n >> m;
  53. vector <set <int> > G(n + 1);
  54.  
  55. for (int i = 1, x, y; i <= m; ++i)
  56. {
  57. fin >> x >> y;
  58. G[x].insert(y);
  59. G[y].insert(x);
  60. }
  61.  
  62. fin >> p >> q >> r;
  63.  
  64. used[p] = true;
  65. X[1] = p;
  66. DFS_Traversal(G, 2, p);
  67.  
  68. fin.close(), fout.close();
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement