Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <time.h>
- #include <unistd.h>
- #include <algorithm>
- #include <map>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <set>
- #include <string>
- #define pb push_back
- #define mp make_pair
- #define ll long long
- #define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
- #define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
- using namespace std;
- vector<int> nxt[111111];
- int curr[6];
- vector< vector<int> > res;
- void find(int u, int num) {
- int x = 0;
- bool connects = false;
- REP(j, nxt[u].size()) {
- REP(k, num) if(curr[k] == nxt[u][j]) x++;
- if(nxt[u][j] == curr[0]) connects = true;
- }
- if((num < 5 && (x != 1)) || (num==5 && x != 2))
- return;
- if(num == 5 && connects == false)
- return;
- if(num == 5) {
- vector<int> cres;
- REP(k, 5) cres.pb(curr[k]);
- sort(cres.begin(), cres.end());
- res.pb(cres);
- return;
- }
- REP(j, nxt[u].size()) {
- int v = nxt[u][j];
- if(v > curr[0] && (num < 4 || v > curr[1])) {
- curr[num] = v;
- find(v, num+1);
- }
- }
- }
- int main() {
- int n,m;
- scanf("%d%d", &n, &m);
- REP(i, m) {
- int u,v;
- scanf("%d%d", &u, &v);
- nxt[u].pb(v);
- nxt[v].pb(u);
- }
- REP(i, n) REP(j, nxt[i].size()) {
- int v = nxt[i][j];
- if(v > i) {
- curr[0] = i; curr[1] = v;
- find(v, 2);
- }
- }
- sort(res.begin(), res.end());
- REP(i, res.size()) {
- REP(j, res[i].size()) {
- printf("%d", res[i][j]);
- if(j != res[i].size()-1) printf(" ");
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement