Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <chrono>
- #include <cmath>
- #include <iostream>
- #include <random>
- #include <vector>
- #include <unordered_set>
- using namespace std;
- int s;
- void check(unordered_set<int>& candidates, unordered_set<int>& compsub, unordered_set<int>& not_c, vector<vector<int>>& graph) {
- if (compsub.size() >= s){
- cout << "YES";
- exit(0);
- }
- bool cont = false;
- for (auto el: not_c){
- bool flag = false;
- for (auto c: candidates){
- if (!graph[c][el]){
- flag = true;
- break;
- }
- }
- if (!flag){
- cont = true;
- break;
- }
- }
- while (!candidates.empty() && !cont){
- auto v = *candidates.begin();
- compsub.insert(v);
- unordered_set<int> new_candidates;
- unordered_set<int> new_not_c;
- for (auto el: candidates){
- if (!graph[el][v] && v != el){
- new_candidates.insert(el);
- }
- }
- for (auto el: not_c){
- if (!graph[el][v] && v != el){
- new_not_c.insert(el);
- }
- }
- if (!new_candidates.empty()){
- check(new_candidates, compsub, new_not_c, graph);
- }
- candidates.erase(v);
- not_c.insert(v);
- compsub.erase(v);
- }
- }
- int main() {
- int v, k;
- cin >> v >> k;
- s = k;
- int e;
- cin >> e;
- unordered_set<int> candidates;
- unordered_set<int> compsub;
- unordered_set<int> not_c;
- vector<vector<int>> graph(v, vector<int>(v, true));
- for (int i = 0; i < v; ++i){
- candidates.insert(i);
- }
- for (int i = 0; i < e; ++i) {
- int v1, v2;
- cin >> v1 >> v2, --v1, --v2;
- graph[v1][v2] = false;
- graph[v2][v1] = false;
- }
- check(candidates, compsub, not_c, graph);
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement