Advertisement
limimage

BBBBBB

May 26th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 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. int par[N];
  10. vector<vector<int>> ans;
  11. vector<int> vec;
  12. int used;
  13. bool flag = true;
  14.  
  15. int main() {
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(nullptr);
  18. cout.tie(nullptr);
  19. int n, m, b, p;
  20. cin >> n >> m;
  21. while(m--)
  22. {
  23. cin >> b >> p;
  24. par[p-1]+=(1<<(b-1));
  25. }
  26. for (int i = 0; i < n; i++)
  27. vec.push_back(i);
  28. do
  29. {
  30. flag = true;
  31. used = 0;
  32. for (auto el : vec)
  33. {
  34. if ((par[el] & used)!=par[el])
  35. {
  36. flag = false;
  37. break;
  38. }
  39. used+=1<<el;
  40. }
  41. if (flag)
  42. {
  43. ans.push_back(vec);
  44. }
  45. } while (next_permutation(vec.begin(), vec.end()));
  46. if (ans.size())
  47. {
  48. cout << ans.size() << endl;
  49. for (auto a : ans)
  50. {
  51. for (auto el : a)
  52. {
  53. cout << el+1 << " ";
  54. }
  55. cout << endl;
  56. }
  57. }
  58. else cout << "no";
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement