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
54
55
#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>
#define fi first
#define se second

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    vector<bool> V;
    for(int i = 0 ;i < n ;i ++)
    {
        bool x;
        cin>>x;
        V.push_back(x);
    }
    vector<pair<int,int>> pary;
    for(int i = 0 ;i < m ;i ++)
    {
        int a,b;
        cin>>a>>b;
        pary.push_back({--a,--b});
    }
    set<vector<bool>> old,cur,nef;
    cur.insert(V);
    while(!cur.empty())
    {
        for(auto I : cur)
        {
            old.insert(I);
        }
        for(auto I : cur)
        {
            for(auto K : pary)
            {
                if(I[K.fi]==I[K.se])
                {
                    I[K.fi] =  I[K.fi] == true ? false : true;
                    I[K.se] =  I[K.se] == true ? false : true;
                    if(!old.count(I))
                        nef.insert(I);
                    I[K.fi] =  I[K.fi] == true ? false : true;
                    I[K.se] =  I[K.se] == true ? false : true;
                }
            }
        }
        cur.swap(nef);
        nef.clear();
    }
    cout<<old.size();
}