Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cctype>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <deque>
- #include <list>
- #include <set>
- #include <map>
- #include <queue>
- #include <stack>
- #include <string>
- using namespace std;
- #define forn(i, n) for(int (i) = 0; (i) < (n); ++(i))
- #define mp make_pair
- #define vi vector<int>
- #define vvi vector<vector<int>>
- #define vvvi vector<vector<vector<int>>>
- #define pb push_back
- #define li long long
- #define geta(_type, _x, _n)\
- vector<_type> _x(_n);\
- for (int _i = 0; _i < _n; ++_i)\
- cin >> _x[_i];
- vector<set<int>> a;
- set<int> compsub;
- int ans = 0;
- set<int> compsub_ans;
- void gen(set<int> candidates, set<int> used)
- {
- while (!candidates.empty())
- {
- set<int>::iterator it = candidates.begin();
- compsub.insert(*it);
- set<int> n_candidates;
- set<int> n_used;
- for (set<int>::iterator it2 = candidates.begin(); it2 != candidates.end(); it2++)
- if (a[(*it2)].find(*it) != a[(*it2)].end())
- n_candidates.insert(*it2);
- if (!used.empty())
- {
- for (set<int>::iterator it2 = used.begin(); it2 != used.end(); it2++)
- if (a[(*it2)].find(*it) != a[(*it2)].end())
- n_used.insert(*it2);
- }
- if (n_candidates.empty() && n_used.empty())
- {
- if (compsub.size() > ans)
- ans = compsub.size(), compsub_ans = compsub;
- }
- else
- gen(n_candidates, n_used);
- used.insert(*it);
- compsub.erase(*it);
- candidates.erase(it);
- }
- }
- bool is_click(set<int> click)
- {
- if (click.empty())
- return true;
- for (set<int>::iterator it = click.begin(); it != click.end(); it++)
- for (set<int>::iterator it2 = click.begin(); it2 != click.end(); it2++)
- if ((it != it2) && (a[(*it)].find(*it2) == a[(*it)].end()))
- return false;
- return true;
- }
- void check_click(set<int> click)
- {
- forn (i, a.size())
- {
- set<int> click2 = click;
- if (click2.find(i) == click2.end())
- {
- click2.insert(i);
- if (is_click(click2))
- {
- if (click2.size() > ans)
- ans = click2.size(), compsub_ans = click2;
- check_click(click2);
- }
- }
- }
- }
- int main()
- {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n, m;
- cin >> n >> m;
- a.resize(n);
- set<int> candidates;
- set<int> used;
- forn(i, n)
- candidates.insert(i);
- forn(i, m)
- {
- int x, y;
- cin >> x >> y;
- x--, y--;
- a[x].insert(y);
- a[y].insert(x);
- }
- gen(candidates, used);
- cout << "Приближенное вычисление: " << endl << "Размер максимальной клики: " << ans << endl << "Клика: ";
- for (set<int>::iterator it = compsub_ans.begin(); it != compsub_ans.end(); it++)
- cout << (*it) + 1 << ' ';
- cout << endl << endl;
- set<int> new_st;
- check_click(new_st);
- cout << "Точное вычисление: " << endl << "Размер максимальной клики: " << ans << endl << "Клика: ";
- for (set<int>::iterator it = compsub_ans.begin(); it != compsub_ans.end(); it++)
- cout << (*it) + 1 << ' ';
- return !(cout << endl);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement