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;
- vector<int> par[N];
- vector<vector<int>> ans;
- vector<bool> 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].push_back(b);
- }
- vector<int> vec;
- for (int i = 1; i <= n; i++)
- {
- vec.push_back(i);
- }
- do
- {
- flag = true;
- used = vector<bool>(n, false);
- for (auto v : vec)
- {
- for (auto pr: par[v])
- {
- if (!used[pr])
- {
- flag = false;
- break;
- }
- }
- if(!flag)
- break;
- used[v] = true;
- }
- 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 << " ";
- }
- cout << endl;
- }
- }
- else cout << "no";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement