SHARE
TWEET

Untitled

a guest Nov 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5. int n;
  6. char c;
  7. vector<set<int>> g;
  8. deque<int> q;
  9. int main() {
  10.     freopen("fullham.in", "r", stdin);
  11.     freopen("fullham.out", "w", stdout);
  12.     cin >> n;
  13.     g.resize(n + 1);
  14.     for (int i = 1; i < n + 1; ++i) {
  15.         for (int j = 1; j < i; ++j) {
  16.             cin >> c;
  17.             if (c == '1') {
  18.                 g[i].insert(j);
  19.                 g[j].insert(i);
  20.             }
  21.         }
  22.     }
  23.     for (int i = 0; i < n; ++i) {
  24.         q.push_back(i + 1);
  25.     }
  26.     for (int k = 0; k < n * (n - 1) + 1; ++k) {
  27.         if (g[q.front()].find(q[1]) == g[q.front()].end()) {
  28.             int i = 2;
  29.             while (g[q.front()].find(q[i]) == g[q.front()].end() ||
  30.                     g[q[1]].find(q[i + 1]) == g[q[1]].end()) {
  31.                 ++i;
  32.             }
  33.             reverse(&q[1], &q[i + 1]);
  34.         }
  35.         q.push_back(q.front());
  36.         q.pop_front();
  37.     }
  38.     for (auto an : q) {
  39.         cout << an << " ";
  40.     }
  41.     return 0;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top