Advertisement
limimage

BBBB

May 26th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. using ll = long long;
  7. constexpr int N = 13;
  8.  
  9. vector<int> par[N];
  10. vector<vector<int>> ans;
  11. vector<bool> used;
  12. bool flag = true;
  13.  
  14. int main() {
  15. ios_base::sync_with_stdio(false);
  16. cin.tie(nullptr);
  17. cout.tie(nullptr);
  18. int n, m, b, p;
  19. cin >> n >> m;
  20. while(m--)
  21. {
  22. cin >> b >> p;
  23. par[p].push_back(b);
  24. }
  25. vector<int> vec;
  26. for (int i = 1; i <= n; i++)
  27. {
  28. vec.push_back(i);
  29. }
  30. do
  31. {
  32. flag = true;
  33. used = vector<bool>(n, false);
  34. for (auto v : vec)
  35. {
  36. for (auto pr: par[v])
  37. {
  38. if (!used[pr])
  39. {
  40. flag = false;
  41. break;
  42. }
  43. }
  44. if(!flag)
  45. break;
  46. used[v] = true;
  47. }
  48. if (flag)
  49. {
  50. ans.push_back(vec);
  51. }
  52. } while (next_permutation(vec.begin(), vec.end()));
  53. if (ans.size())
  54. {
  55. cout << ans.size() << endl;
  56. for (auto a : ans)
  57. {
  58. for (auto el : a)
  59. {
  60. cout << el << " ";
  61. }
  62. cout << endl;
  63. }
  64. }
  65. else cout << "no";
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement