Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- constexpr int N = 13;
- int par[N];
- vector<vector<int>> ans;
- vector<int> vec;
- int used;
- bool flag = true;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n, m, b, p;
- cin >> n >> m;
- while(m--)
- {
- cin >> b >> p;
- par[p-1]+=(1<<(b-1));
- }
- for (int i = 0; i < n; i++)
- vec.push_back(i);
- do
- {
- flag = true;
- used = 0;
- for (auto el : vec)
- {
- if ((par[el] & used)!=par[el])
- {
- flag = false;
- break;
- }
- used+=1<<el;
- }
- if (flag)
- {
- ans.push_back(vec);
- }
- } while (next_permutation(vec.begin(), vec.end()));
- if (ans.size())
- {
- cout << ans.size() << endl;
- for (auto a : ans)
- {
- for (auto el : a)
- {
- cout << el+1 << " ";
- }
- cout << endl;
- }
- }
- else cout << "no";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement