#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
long long n,m;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
unsigned int bsize=(unsigned long long)n;
bitset<1000>s0;
for(int i=0; i<n; i++){
int inp;
cin>>inp;
s0[i]=inp;
}
vector<pair<long long,long long>>edg(m);
unordered_map<bitset<1000>,int>stanys;
queue<bitset<1000>>stanyq;
stanys[s0]=1;
stanyq.push(s0);
for(int i=0; i<m; i++){
cin>>edg[i].F>>edg[i].S;
edg[i].F--;
edg[i].S--;
}
while(!stanyq.empty()){
bitset<1000> cstan=stanyq.front();
stanyq.pop();
for(int i=0; i<m; i++){
bitset<1000> b1,b2;
b1[edg[i].F]=1;
b2[edg[i].S]=1;
if((cstan[edg[i].F]==1&&cstan[edg[i].S]==1)||(cstan[edg[i].F]==0&&cstan[edg[i].S]==0)){
bitset<1000> nstan=cstan;
nstan.flip(edg[i].F);
nstan.flip(edg[i].S);
if(stanys.find(nstan)==stanys.end()){
stanys[nstan]=1;
stanyq.push(nstan);
}
}
}
}
cout<<stanys.size()<<"\n";
/*for(auto x : stanys){
cout<<x<<"\n";
}*/
}
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 | #include<bits/stdc++.h> using namespace std; #define F first #define S second long long n,m; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; unsigned int bsize=(unsigned long long)n; bitset<1000>s0; for(int i=0; i<n; i++){ int inp; cin>>inp; s0[i]=inp; } vector<pair<long long,long long>>edg(m); unordered_map<bitset<1000>,int>stanys; queue<bitset<1000>>stanyq; stanys[s0]=1; stanyq.push(s0); for(int i=0; i<m; i++){ cin>>edg[i].F>>edg[i].S; edg[i].F--; edg[i].S--; } while(!stanyq.empty()){ bitset<1000> cstan=stanyq.front(); stanyq.pop(); for(int i=0; i<m; i++){ bitset<1000> b1,b2; b1[edg[i].F]=1; b2[edg[i].S]=1; if((cstan[edg[i].F]==1&&cstan[edg[i].S]==1)||(cstan[edg[i].F]==0&&cstan[edg[i].S]==0)){ bitset<1000> nstan=cstan; nstan.flip(edg[i].F); nstan.flip(edg[i].S); if(stanys.find(nstan)==stanys.end()){ stanys[nstan]=1; stanyq.push(nstan); } } } } cout<<stanys.size()<<"\n"; /*for(auto x : stanys){ cout<<x<<"\n"; }*/ } |
English