Advertisement
Dang_Quan_10_Tin

DU LỊCH

Jul 11th, 2022
1,115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5. using ld = long double;
  6. using ull = unsigned long long;
  7.  
  8. constexpr bool typetest = 0;
  9. constexpr int N = 1e5 + 5;
  10. constexpr int M = 20 + 5;
  11. constexpr int mod = 1e9 + 7;
  12.  
  13. int n, m;
  14. vector<int> a[M];
  15. bitset<N> go[M], dontgo[M];
  16. int b[N];
  17. int ck[M];
  18. int cnt[1 << 20];
  19.  
  20. ll f[1 << 20];
  21.  
  22. void Read()
  23. {
  24.     cin >> n >> m;
  25.  
  26.     for (int i = 0; i < m; ++i)
  27.     {
  28.         int t;
  29.         cin >> t;
  30.         a[i].resize(t);
  31.  
  32.         for (auto &j : a[i])
  33.         {
  34.             cin >> j;
  35.             if (j > 0)
  36.                 go[i][j] = 1, b[j] |= 1 << i;
  37.             else
  38.                 dontgo[i][-j] = 1, b[-j] |= 1 << i;
  39.         }
  40.     }
  41. }
  42.  
  43. #define bit(i, x) (((x) >> (i)) & 1)
  44.  
  45. ll Pow(ll a, ll b)
  46. {
  47.     ll ans(1);
  48.  
  49.     for (; b; b >>= 1)
  50.     {
  51.         if (b & 1)
  52.             ans = ans * a % mod;
  53.         a = a * a % mod;
  54.     }
  55.  
  56.     return ans;
  57. }
  58.  
  59. void Solve()
  60. {
  61.     for (int i = 0; i < m; ++i)
  62.         for (int j = 0; j < m; ++j)
  63.             if ((go[j] & dontgo[i]).any() || (dontgo[j] & go[i]).any())
  64.                 ck[i] |= 1 << j;
  65.  
  66.     for (int i = 1; i <= n; ++i)
  67.         ++cnt[b[i] ^ ((1 << m) - 1)];
  68.  
  69.     for (int i = 0; i < m; ++i)
  70.         for (int j = 0; j < (1 << m); ++j)
  71.             if (bit(i, j))
  72.                 cnt[j ^ (1 << i)] += cnt[j];
  73.  
  74.     ll ans(0);
  75.  
  76.     for (int i = 0; i < (1 << m); ++i)
  77.     {
  78.  
  79.         for (int t = 0; t < m; ++t)
  80.             if (bit(t, i) && (ck[t] & i) > 0)
  81.                 goto done;
  82.  
  83.         (ans += ((__builtin_popcount(i) & 1) ? -1 : 1) * Pow(2, cnt[i])) %= mod;
  84.  
  85.     done:;
  86.     }
  87.  
  88.     cout << (ans + mod) % mod;
  89. }
  90.  
  91. int32_t main()
  92. {
  93.     ios::sync_with_stdio(0);
  94.     cin.tie(0);
  95.     cout.tie(0);
  96.     if (fopen("tests.inp", "r"))
  97.     {
  98.         freopen("test.inp", "r", stdin);
  99.         freopen("test.out", "w", stdout);
  100.     }
  101.     int t(1);
  102.     if (typetest)
  103.         cin >> t;
  104.     for (int _ = 1; _ <= t; ++_)
  105.     {
  106.         // cout << "Case #" << _ << ": ";
  107.         Read();
  108.         Solve();
  109.     }
  110.     // cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  111. }
  112.  
  113. /*
  114.  */
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement