Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <set>
  6. #include <cassert>
  7. #include <unordered_set>
  8. #include <random>
  9.  
  10. using namespace std;
  11.  
  12. vector<vector<int>> gr;
  13.  
  14. mt19937 rr(random_device{}());
  15.  
  16. int main() {
  17.     /*ios_base::sync_with_stdio(false);
  18.      cin.tie(NULL);
  19.      cout.tie(NULL);*/
  20.     freopen("input.txt", "r", stdin);
  21.     // freopen("output.txt", "w", stdout);
  22.    
  23.     int n, m;
  24.     cin >> n >> m;
  25.     gr.resize(n);
  26.     for (int i = 0; i < n; ++i) {
  27.         int a, b;
  28.         cin >> a >> b;
  29.         --a;
  30.         --b;
  31.         gr[a].push_back(b);
  32.         gr[b].push_back(a);
  33.     }
  34.     vector<int> v(n);
  35.     vector<int> mx(n);
  36.     int ans = 0;
  37.     for (int i = 0; i < n; ++i)
  38.         v[i] = i;
  39.     for (int i = 0; i < 1e5; ++i) {
  40.         shuffle(v.begin(), v.end(), rr);
  41.         for (int cnt = n; cnt > 0; --cnt) {
  42.             unordered_set<int> e;
  43.             if (cnt <= ans)
  44.                 continue;
  45.             for (int j = 0; j < cnt; ++j)
  46.                 e.insert(v[j]);
  47.             bool fl = true;
  48.             for (int j = 0; j < cnt; ++j) {
  49.                 int cnt1 = 0;
  50.                 for (auto x : gr[v[j]]) {
  51.                     if (e.find(x) != e.end())
  52.                         ++cnt1;
  53.                 }
  54.                 if (cnt1 < cnt/2) {
  55.                     fl = false;
  56.                     break;
  57.                 }
  58.             }
  59.             if (fl && cnt > ans) {
  60.                 ans = cnt;
  61.                 mx = v;
  62.             }
  63.         }
  64.     }
  65.     cout << ans << "\n";
  66.     for (int i = 0; i < ans; ++i)
  67.         cout << mx[i] + 1 << " ";
  68.     cout << "\n";
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement