Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7. #include <algorithm>
  8. #include <map>
  9. #include <queue>
  10. #include <stack>
  11. #include <vector>
  12. #include <set>
  13. #include <string>
  14.  
  15. #define pb push_back
  16. #define mp make_pair
  17. #define ll long long
  18. #define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
  19. #define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
  20.  
  21. using namespace std;
  22.  
  23. vector<int> nxt[111111];
  24. int curr[6];
  25. vector< vector<int> > res;
  26.  
  27. void find(int u, int num) {
  28.     int x = 0;
  29.     bool connects = false;
  30.     REP(j, nxt[u].size()) {
  31.         REP(k, num) if(curr[k] == nxt[u][j]) x++;
  32.         if(nxt[u][j] == curr[0]) connects = true;
  33.     }
  34.     if((num < 5 && (x != 1)) || (num==5 && x != 2))
  35.         return;
  36.     if(num == 5 && connects == false)
  37.         return;
  38.     if(num == 5) {
  39.         vector<int> cres;
  40.         REP(k, 5) cres.pb(curr[k]);
  41.         sort(cres.begin(), cres.end());
  42.         res.pb(cres);
  43.         return;
  44.     }
  45.     REP(j, nxt[u].size()) {
  46.         int v = nxt[u][j];
  47.         if(v > curr[0] && (num < 4 || v > curr[1])) {
  48.             curr[num] = v;
  49.             find(v, num+1);
  50.         }
  51.     }
  52. }
  53.  
  54. int main() {
  55.     int n,m;
  56.     scanf("%d%d", &n, &m);
  57.     REP(i, m) {
  58.         int u,v;
  59.         scanf("%d%d", &u, &v);
  60.         nxt[u].pb(v);
  61.         nxt[v].pb(u);
  62.     }
  63.     REP(i, n) REP(j, nxt[i].size()) {
  64.         int v = nxt[i][j];
  65.         if(v > i) {
  66.             curr[0] = i; curr[1] = v;
  67.             find(v, 2);
  68.         }
  69.     }
  70.     sort(res.begin(), res.end());
  71.     REP(i, res.size()) {
  72.         REP(j, res[i].size()) {
  73.             printf("%d", res[i][j]);
  74.             if(j != res[i].size()-1) printf(" ");
  75.         }
  76.         printf("\n");
  77.     }
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement