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
#include <cstdio>
#include <utility>
#include <vector>
#include <unordered_set>
#include <cstdint>
#include <deque>
#include <iostream>

using namespace std;

int n,m;
#define MAX_N  200010
#define MAX_M  200010

int state[MAX_N];

pair<int, int> prze[MAX_M];
__uint128_t M[MAX_M];
__uint128_t one = 1;

namespace std {
template<>
struct hash<__uint128_t> {
    size_t operator()(__uint128_t var) const {
        return std::hash<uint64_t>{}((uint64_t)var ^ (uint64_t)(var >> 64));
    }
};
}

int main() {
    scanf("%d %d", &n ,&m);
    for(int i=0;i<n;i++) scanf("%d", &state[i]);
    for(int i=0;i<m;i++) scanf("%d %d", &prze[i].first, &prze[i].second);

    for(int i=0;i<m;i++) {
        M[i]=(one << (prze[i].first-1)) | (one << (prze[i].second -1));
    } 
    __uint128_t s = 0;
    unordered_set<__uint128_t> visited;
    deque<__uint128_t> queue;
    for(int i=0;i<n;i++) {
        if (state[i]) s|=(one << i);
    }
    queue.push_back(s);
    while (!queue.empty()) {
        int size = queue.size();
        for(int i=0;i<size;i++) {
            auto s = queue.front();
            queue.pop_front();
            if (visited.count(s)) continue;
            visited.insert(s);
            for(int i=0;i<m;i++) {
                if((M[i] & s) == 0 || (M[i] & s) == M[i]) queue.push_back(s^M[i]);
            }
        }
    }
    cout << visited.size() << "\n";
    
}