Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <array>
- #include <algorithm>
- using namespace std;
- static int n;
- static vector<vector<bool> > binds;
- static array<int, 5> complex;
- static vector<array<int, 5> > results;
- void load()
- {
- cin >> n;
- for(int i = 0; i < n; i++)
- {
- binds.push_back(vector<bool>(n));
- }
- int m, a, b;
- cin >> m;
- for(int i = 0; i < m; i++)
- {
- cin >> a >> b;
- binds[a][b] = true;
- binds[b][a] = true;
- }
- }
- void search(int phase, int node, int increments)
- {
- if(increments == 3) return;
- if(phase == 5)
- {
- results.push_back(complex);
- sort(results.back().begin(), results.back().end());
- return;
- }
- for(int i = 0; i < n; i++)
- {
- bool isIn = false;
- for(int j = 0; j < phase; j++)
- {
- if(complex[j] == i)
- {
- isIn = true;
- break;
- }
- }
- if(isIn)
- {
- continue;
- }
- if(binds[node][i]
- && (i > complex[0])
- && (phase < 2 || !binds[i][complex[phase - 2]])
- && (phase < 3 || !binds[i][complex[phase - 3]])
- && (phase < 4 || binds[i][complex[0]])
- )
- {
- int nextInc = increments;
- if(i > node)
- {
- nextInc++;
- }
- complex[phase] = i;
- search(phase + 1, i, nextInc);
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(false);
- load();
- for(int i = 0; i < n; i++)
- {
- complex[0] = i;
- search(1, i, 0);
- sort(results.begin(), results.end());
- for(auto res : results)
- {
- for(int j = 0; j < 5; j++)
- {
- cout << res[j] << " ";
- }
- cout << endl;
- }
- results.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement