#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i,a,b) for(int i=a; i<=b; ++i) #define pb push_back constexpr int MAX_N=2e5+14, MAX_M=3e5+14, MOD=1e9+7;// !!to small MAX_N ll N, M, rres=1; vector<int> edg[MAX_N]; unordered_set<bitset<MAX_N>> cmb; bitset<MAX_N> fCmb; void Input(){ int a,b; cin>>N>>M; FOR(i,0,N-1) cin>>a, fCmb[i]=a; FOR(i,0,M-1) cin>>a>>b, edg[--a].pb(--b), edg[b].pb(a); } void DFS(bitset<MAX_N> cCmb){ // FOR(i,0,N-1) cout<<cCmb[i]<<" "; cout<<"\n"; cmb.insert(cCmb); FOR(cV,0,N-1){ cCmb^=1<<cV; for(auto nV:edg[cV]){ cCmb^=1<<nV; if(cCmb[cV]==cCmb[nV]&&!cmb.count(cCmb)) DFS(cCmb); cCmb^=1<<nV; } cCmb^=1<<cV; } } void Solve(){ DFS(fCmb); cout<<(cmb.size())%MOD<<"\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); Input(); Solve(); }
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 | #include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i,a,b) for(int i=a; i<=b; ++i) #define pb push_back constexpr int MAX_N=2e5+14, MAX_M=3e5+14, MOD=1e9+7;// !!to small MAX_N ll N, M, rres=1; vector<int> edg[MAX_N]; unordered_set<bitset<MAX_N>> cmb; bitset<MAX_N> fCmb; void Input(){ int a,b; cin>>N>>M; FOR(i,0,N-1) cin>>a, fCmb[i]=a; FOR(i,0,M-1) cin>>a>>b, edg[--a].pb(--b), edg[b].pb(a); } void DFS(bitset<MAX_N> cCmb){ // FOR(i,0,N-1) cout<<cCmb[i]<<" "; cout<<"\n"; cmb.insert(cCmb); FOR(cV,0,N-1){ cCmb^=1<<cV; for(auto nV:edg[cV]){ cCmb^=1<<nV; if(cCmb[cV]==cCmb[nV]&&!cmb.count(cCmb)) DFS(cCmb); cCmb^=1<<nV; } cCmb^=1<<cV; } } void Solve(){ DFS(fCmb); cout<<(cmb.size())%MOD<<"\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); Input(); Solve(); } |