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;
- using namespace std::literals::chrono_literals;
- void check(bool &flag, int needed, vector<int> &taken, unordered_set<int>& permissed, vector<int> &order, int now, vector<vector<int>>& graph) {
- if (needed == 0) {
- flag = true;
- }
- if (flag || now == order.size() || needed > order.size() - taken.size() || needed > taken.size() + permissed.size()) {
- return;
- }
- if (!permissed.contains(now)){
- check(flag, needed, taken, permissed, order, now + 1, graph);
- } else {
- vector<int> last_del;
- for (auto el: graph[now]){
- if (permissed.contains(el) && el > now){
- last_del.emplace_back(el);
- }
- }
- if (needed > taken.size() + permissed.size() - last_del.size()){
- return;
- }
- for (auto el: last_del){
- permissed.erase(el);
- }
- check(flag, needed - 1, taken, permissed, order, now + 1, graph);
- if (flag){
- return;
- } else {
- for (auto el: last_del){
- permissed.insert(el);
- }
- }
- }
- }
- int main() {
- int v, k;
- cin >> v >> k;
- vector<vector<int>> graph(v);
- vector<int> deg(v, 0);
- int e;
- cin >> e;
- for (int i = 0; i < e; ++i) {
- int v1, v2;
- cin >> v1 >> v2, --v1, --v2;
- ++deg[v1];
- ++deg[v2];
- graph[v1].emplace_back(v2);
- graph[v2].emplace_back(v1);
- }
- vector<int> order;
- unordered_set<int> permissed;
- for (int i = 0; i < v; ++i) {
- order.emplace_back(i);
- permissed.insert(i);
- }
- sort(order.begin(), order.end(), [&](auto v1, auto v2) { return deg[v1] < deg[v2]; });
- bool flag = false;
- vector<int> taken;
- check(flag, k, taken, permissed, order, 0, graph);
- if (flag){
- cout << "YES";
- } else {
- cout << "NO";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement