#include <bits/stdc++.h> using namespace std; #define f first #define s second #define ll long long constexpr int maxn=200000+7; constexpr int maxm=400000+7; constexpr int mod=1e9 + 7; int n,m; bool x; int a,b; vector<pair<int,int>>vec; vector<bool> input; vector<bool> e; map<vector<bool>,bool>have; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1;i<=n;++i) { cin>>x; input.push_back(x); } for(int i=1;i<=m;++i) { cin>>a>>b; vec.push_back({a,b}); } have[input]=1; for(int iter=1;iter*m<=2e7;++iter) { random_shuffle(vec.begin(), vec.end()); e=input; for(auto &u: vec) if(e[u.f]==e[u.s]) e[u.f]=e[u.s]=!e[u.s]; have[e]=1; } cout<<have.size()%mod; return 0; }
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 51 52 53 | #include <bits/stdc++.h> using namespace std; #define f first #define s second #define ll long long constexpr int maxn=200000+7; constexpr int maxm=400000+7; constexpr int mod=1e9 + 7; int n,m; bool x; int a,b; vector<pair<int,int>>vec; vector<bool> input; vector<bool> e; map<vector<bool>,bool>have; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1;i<=n;++i) { cin>>x; input.push_back(x); } for(int i=1;i<=m;++i) { cin>>a>>b; vec.push_back({a,b}); } have[input]=1; for(int iter=1;iter*m<=2e7;++iter) { random_shuffle(vec.begin(), vec.end()); e=input; for(auto &u: vec) if(e[u.f]==e[u.s]) e[u.f]=e[u.s]=!e[u.s]; have[e]=1; } cout<<have.size()%mod; return 0; } |