Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- using ld = long double;
- using ull = unsigned long long;
- constexpr bool typetest = 0;
- constexpr int N = 1e5 + 5;
- constexpr int M = 20 + 5;
- constexpr int mod = 1e9 + 7;
- int n, m;
- vector<int> a[M];
- bitset<N> go[M], dontgo[M];
- int b[N];
- int ck[M];
- int cnt[1 << 20];
- ll f[1 << 20];
- void Read()
- {
- cin >> n >> m;
- for (int i = 0; i < m; ++i)
- {
- int t;
- cin >> t;
- a[i].resize(t);
- for (auto &j : a[i])
- {
- cin >> j;
- if (j > 0)
- go[i][j] = 1, b[j] |= 1 << i;
- else
- dontgo[i][-j] = 1, b[-j] |= 1 << i;
- }
- }
- }
- #define bit(i, x) (((x) >> (i)) & 1)
- ll Pow(ll a, ll b)
- {
- ll ans(1);
- for (; b; b >>= 1)
- {
- if (b & 1)
- ans = ans * a % mod;
- a = a * a % mod;
- }
- return ans;
- }
- void Solve()
- {
- for (int i = 0; i < m; ++i)
- for (int j = 0; j < m; ++j)
- if ((go[j] & dontgo[i]).any() || (dontgo[j] & go[i]).any())
- ck[i] |= 1 << j;
- for (int i = 1; i <= n; ++i)
- ++cnt[b[i] ^ ((1 << m) - 1)];
- for (int i = 0; i < m; ++i)
- for (int j = 0; j < (1 << m); ++j)
- if (bit(i, j))
- cnt[j ^ (1 << i)] += cnt[j];
- ll ans(0);
- for (int i = 0; i < (1 << m); ++i)
- {
- for (int t = 0; t < m; ++t)
- if (bit(t, i) && (ck[t] & i) > 0)
- goto done;
- (ans += ((__builtin_popcount(i) & 1) ? -1 : 1) * Pow(2, cnt[i])) %= mod;
- done:;
- }
- cout << (ans + mod) % mod;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen("tests.inp", "r"))
- {
- freopen("test.inp", "r", stdin);
- freopen("test.out", "w", stdout);
- }
- int t(1);
- if (typetest)
- cin >> t;
- for (int _ = 1; _ <= t; ++_)
- {
- // cout << "Case #" << _ << ": ";
- Read();
- Solve();
- }
- // cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement