Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <array>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. static int n;
  10. static vector<set<int> > binds;
  11. static array<int, 5> complex;
  12. static vector<array<int, 5> > results;
  13.  
  14. void load()
  15. {
  16.     cin >> n;
  17.     for(int i = 0; i < n; i++)
  18.     {
  19.         binds.push_back(set<int>());
  20.     }
  21.  
  22.     int m, a, b;
  23.     cin >> m;
  24.     for(int i = 0; i < m; i++)
  25.     {
  26.         cin >> a >> b;
  27.         binds[a].insert(b);
  28.         binds[b].insert(a);
  29.     }
  30. }
  31.  
  32. void search(int phase, int node, int increments)
  33. {
  34.     for(int i : binds[node])
  35.     {
  36.         if(i < complex[0]) continue;
  37.  
  38.         int connections = 0;
  39.         bool close = false;
  40.         for(auto bind : binds[i])
  41.         {
  42.             for(int j = 0; j < phase; j++)
  43.             {
  44.                 if(bind == complex[j]) connections++;
  45.             }
  46.             if(bind == complex[0]) close = true;
  47.         }
  48.  
  49.         if((phase < 4 && connections != 1) || (phase == 4 && (connections != 2 || !close))) continue;
  50.  
  51.         if(increments < 2 || i < node)
  52.         {
  53.             complex[phase] = i;
  54.             if(phase == 4)
  55.             {
  56.                 results.push_back(complex);
  57.                 sort(results.back().begin(), results.back().end());
  58.                 continue;
  59.             }
  60.  
  61.             search(phase + 1, i, (i < node) ? increments : increments + 1);
  62.         }
  63.     }
  64. }
  65. int main()
  66. {
  67.     ios::sync_with_stdio(false);
  68.     load();
  69.  
  70.     for(int i = 0; i < n; i++)
  71.     {
  72.         for(auto k : binds[i])
  73.         {
  74.             if(k < i) continue;
  75.  
  76.             complex[0] = i;
  77.             complex[1] = k;
  78.             search(2, k, 1);
  79.  
  80.             sort(results.begin(), results.end());
  81.             for(auto res : results)
  82.             {
  83.                 for(int j = 0; j < 5; j++)
  84.                 {
  85.                     cout << res[j] << " ";
  86.                 }
  87.                 cout << endl;
  88.             }
  89.             results.clear();
  90.         }
  91.     }
  92.  
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement