#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2,tune=native") #pragma GCC target("sse,sse2,abm,mmx,sse3,tune=native") using namespace std; typedef long long lld; typedef pair<int, int> pii; typedef pair<lld, lld> pll; #define ff first #define dd second #define mp make_pair #define pb push_back #define sz size() #define For(i, s, a) for(int i = s; i < a; ++i) #define all(x) (x).begin(), (x).end() #define make_unique(x) (x).erase(unique(all(x)), (x).end()) vector<pii> c; bitset<(1 << 28)>ct; void dfs(int mask) { ct[mask] = 1; for (auto s : c) { if (((mask & (1 << s.ff)) > 0) == ((mask & (1 << s.dd)) > 0)) { auto m2 = mask ^ (1 << s.ff) ^ (1 << s.dd); if (!ct[m2]) dfs(m2); } } } int main() { int n, m; scanf("%d%d", &n, &m); int mask = 0; For (i, 0, n) { int g; scanf("%d", &g); if (g) mask ^= (1 << i); } c.resize(m); For (i, 0, m) { scanf("%d%d", &c[i].ff, &c[i].dd); c[i].ff--; c[i].dd--; } dfs(mask); printf("%d", ct.count()); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2,tune=native") #pragma GCC target("sse,sse2,abm,mmx,sse3,tune=native") using namespace std; typedef long long lld; typedef pair<int, int> pii; typedef pair<lld, lld> pll; #define ff first #define dd second #define mp make_pair #define pb push_back #define sz size() #define For(i, s, a) for(int i = s; i < a; ++i) #define all(x) (x).begin(), (x).end() #define make_unique(x) (x).erase(unique(all(x)), (x).end()) vector<pii> c; bitset<(1 << 28)>ct; void dfs(int mask) { ct[mask] = 1; for (auto s : c) { if (((mask & (1 << s.ff)) > 0) == ((mask & (1 << s.dd)) > 0)) { auto m2 = mask ^ (1 << s.ff) ^ (1 << s.dd); if (!ct[m2]) dfs(m2); } } } int main() { int n, m; scanf("%d%d", &n, &m); int mask = 0; For (i, 0, n) { int g; scanf("%d", &g); if (g) mask ^= (1 << i); } c.resize(m); For (i, 0, m) { scanf("%d%d", &c[i].ff, &c[i].dd); c[i].ff--; c[i].dd--; } dfs(mask); printf("%d", ct.count()); } |