Advertisement
kolbka_

Untitled

Dec 17th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include <iostream>
  5. #include <cassert>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <unordered_map>
  9. #include "optimization.h"
  10. #include <map>
  11.  
  12. #define all(a) a.begin, a.end()
  13. using namespace std;
  14.  
  15. int main() {
  16.  
  17.     int counter = 0;
  18.     int n, x, y;
  19.     n = readInt();
  20.     x = readInt();
  21.     y = readInt();
  22.     vector<bool> mark((1 << (n+1)), false);
  23.     vector<bool> deleted((1 << (n + 1)), false);
  24.     for (int i = 0; i < x; i++) {
  25.         int count = readInt();
  26.         unsigned int cur = 0;
  27.         for (int j = 0; j < count; j++) {
  28.             int temp = readInt();
  29.             temp--;
  30.             cur |= (1 << temp);
  31.         }
  32.         mark[cur] = true;
  33.     }
  34.     vector<int> ready((1<<(n+1)));
  35.     for (int i = 0; i < y; i++) {
  36.         int count = readInt();
  37.         unsigned int cur = 0;
  38.         for (int j = 0; j < count; j++) {
  39.             int temp = readInt();
  40.             temp--;
  41.             cur |= (1 << temp);
  42.         }
  43.         deleted[cur] = true;
  44.     }
  45.  
  46.     for (int k = (1 << (n)) - 1; k >= 0; --k) {
  47.         if ((mark[k] && ready[k] == 0) || deleted[k]) {
  48.             int value = -1;
  49.             if (mark[k] && ready[k] == 0 && !deleted[k]) value = 1;
  50.             for (int B = k; B > 0; B--, B &= k) {
  51.                 if (ready[B] != -1) {
  52.                     ready[B] = value;
  53.                 }
  54.             }
  55.             if (ready[0] != -1) {
  56.                 ready[0] = value;
  57.             }
  58.  
  59.         }
  60.     }
  61.     for (int i = 0; i < (1 << (n+1)); i++){
  62.         if (ready[i] == 1) counter++;
  63.     }
  64.     writeInt(counter);
  65. }
  66.  
  67.  
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement