Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int N = 1 << 25;
- long long ns_for_v[50];
- int dp1[N];
- int first_bit[N];
- void count_dp1(int L, int R) {
- for (int i = 0; i < (R - L); i++) {
- first_bit[1 << i] = i;
- }
- for (int i = 1; i < (1 << (R - L)); i++) {
- auto vi = i ^ (i & (i - 1));
- int v = first_bit[vi] + L;
- dp1[i] = max(dp1[i ^ vi], 1 + dp1[(i ^ vi) & (~ns_for_v[v])]);
- }
- }
- int V, S;
- void req(int cnt, long long dp2, int M) {
- if (M == V) {
- int ans = cnt + dp1[~dp2 & ((1 << (V / 2)) - 1)];
- if (ans >= S) {
- cout << "YES\n";
- exit(0);
- }
- return;
- }
- req(cnt, dp2, M + 1);
- if ((dp2 >> M) & 1) {
- return;
- } else {
- req(cnt + 1, dp2 | ns_for_v[M], M + 1);
- }
- }
- int main() {
- cin >> V >> S;
- int E;
- cin >> E;
- for (int i = 0; i < E; ++i) {
- int a, b;
- cin >> a >> b;
- a--, b--;
- ns_for_v[a] |= 1LL << b;
- ns_for_v[b] |= 1LL << a;
- }
- count_dp1(0, V / 2);
- req(0, 0, V / 2);
- cout << "NO\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement