Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <array>
- #include <algorithm>
- using namespace std;
- static int n;
- static vector<set<int> > 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(set<int>());
- }
- int m, a, b;
- cin >> m;
- for(int i = 0; i < m; i++)
- {
- cin >> a >> b;
- binds[a].insert(b);
- binds[b].insert(a);
- }
- }
- void search(int phase, int node, int increments)
- {
- for(int i : binds[node])
- {
- if(i < complex[0]) continue;
- int connections = 0;
- bool close = false;
- for(auto bind : binds[i])
- {
- for(int j = 0; j < phase; j++)
- {
- if(bind == complex[j]) connections++;
- }
- if(bind == complex[0]) close = true;
- }
- if((phase < 4 && connections != 1) || (phase == 4 && (connections != 2 || !close))) continue;
- if(increments < 2 || i < node)
- {
- complex[phase] = i;
- if(phase == 4)
- {
- results.push_back(complex);
- sort(results.back().begin(), results.back().end());
- continue;
- }
- search(phase + 1, i, (i < node) ? increments : increments + 1);
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(false);
- load();
- for(int i = 0; i < n; i++)
- {
- for(auto k : binds[i])
- {
- if(k < i) continue;
- complex[0] = i;
- complex[1] = k;
- search(2, k, 1);
- 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