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
56
57
58
59
60
61
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;

vector<pair<int, int>> vec;
vector<int> komb;
map<vector<bool>, int> ma;
long long n, m, w = 1;

void polacz(vector<bool> zar)
{   
    /*for(int i = 0; i < n; i++){
        cout << zar[i] << " ";
    }
    cout << endl;*/
    for(int i = 0; i < m; i++){
        if(zar[vec[i].first] == zar[vec[i].second]){
            if(zar[vec[i].first] == 0){
                zar[vec[i].first] = 1;
                zar[vec[i].second] = 1;
                if(ma[zar] == 0){
                    w++;
                    ma[zar] = 1;
                    polacz(zar);
                }
                zar[vec[i].first] = 0;
                zar[vec[i].second] = 0;
            }else{
                zar[vec[i].first] = 0;
                zar[vec[i].second] = 0;
                if(ma[zar] == 0){
                    w++;
                    ma[zar] = 1;
                    polacz(zar);
                }
                zar[vec[i].first] = 1;
                zar[vec[i].second] = 1;
            }
        }
    }
}

int main()
{
    int a, b;
    cin >> n >> m;
    vector<bool> tab;
    for(int i = 0; i < n; i++){
        cin >> a;
        tab.push_back(a);
    }
    ma[tab] = 1;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        vec.push_back(make_pair(a, b));
    }
    polacz(tab);
    cout << w % 1000000007;
}