Advertisement
anechka_ne_plach

Сильное и независимое

Oct 10th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int N = 1 << 25;
  5.  
  6. long long ns_for_v[50];
  7. int dp1[N];
  8. int first_bit[N];
  9.  
  10. void count_dp1(int L, int R) {
  11.     for (int i = 0; i < (R - L); i++) {
  12.         first_bit[1 << i] = i;
  13.     }
  14.     for (int i = 1; i < (1 << (R - L)); i++) {
  15.         auto vi = i ^ (i & (i - 1));
  16.         int v = first_bit[vi] + L;
  17.         dp1[i] = max(dp1[i ^ vi], 1 + dp1[(i ^ vi) & (~ns_for_v[v])]);
  18.     }
  19. }
  20.  
  21. int V, S;
  22.  
  23. void req(int cnt, long long dp2, int M) {
  24.     if (M == V) {
  25.         int ans = cnt + dp1[~dp2 & ((1 << (V / 2)) - 1)];
  26.         if (ans >= S) {
  27.             cout << "YES\n";
  28.             exit(0);
  29.         }
  30.         return;
  31.     }
  32.     req(cnt, dp2, M + 1);
  33.     if ((dp2 >> M) & 1) {
  34.         return;
  35.     } else {
  36.         req(cnt + 1, dp2 | ns_for_v[M], M + 1);
  37.     }
  38. }
  39.  
  40. int main() {
  41.     cin >> V >> S;
  42.     int E;
  43.     cin >> E;
  44.     for (int i = 0; i < E; ++i) {
  45.         int a, b;
  46.         cin >> a >> b;
  47.         a--, b--;
  48.         ns_for_v[a] |= 1LL << b;
  49.         ns_for_v[b] |= 1LL << a;
  50.     }
  51.     count_dp1(0, V / 2);
  52.     req(0, 0, V / 2);
  53.     cout << "NO\n";
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement