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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

struct op {
    int a, b;
};

inline bool bit_check(unsigned long long n, int k) {
    return (n >> k) & 1LL;
}

inline void bit_set(unsigned long long &n, int k) {
    n |= (1LL << k);
}

inline void bit_clear(unsigned long long &n, int k) {
    n &= ~(1LL << k);
}

int compute(set<string> &uniq, vector<op> &ops) {
    int n = uniq.size();    
    vector<string> v(uniq.begin(), uniq.end());
    for (int i = 0; i < v.size(); i++) {
        string w = v[i];
        for (op &o : ops) {
            if (w[o.a] == w[o.b]) {
                if (w[o.a] == '1') {
                    string z = w;
                    z[o.a] = '0';
                    z[o.b] = '0';
                    if (uniq.count(z) == 0) {
                        v.push_back(z);
                        uniq.insert(z);
                    }
                }
                else {
                    string z = w;
                    z[o.a] = '1';
                    z[o.b] = '1';
                    if (uniq.count(z) == 0) {
                        v.push_back(z);
                        uniq.insert(z);
                    }
                }
            }
        }
    }
    
    return v.size();
}

int compute(set<unsigned long long> &uniq, vector<op> &ops) {
    int n = uniq.size();    
    vector<unsigned long long> v(uniq.begin(), uniq.end());
    for (int i = 0; i < v.size(); i++) {
        unsigned long long w = v[i];
        for (op &o : ops) {
            if (bit_check(w, o.a) == bit_check(w, o.b)) {
                if (bit_check(w, o.a)) {
                    unsigned long long z = w;
                    bit_clear(z, o.a);
                    bit_clear(z, o.b);
                    if (uniq.count(z) == 0) {
                        v.push_back(z);
                        uniq.insert(z);
                    }
                }
                else {
                    unsigned long long z = w;
                    bit_set(z, o.a);
                    bit_set(z, o.b);
                    if (uniq.count(z) == 0) {
                        v.push_back(z);
                        uniq.insert(z);
                    }
                }
            }
        }
    }
    
    return v.size();
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    string s(n, '_');
    unsigned long long b = 0;
    for (int i = 0, e; i < n; i++) {
        cin >> e;
        s[i] = e ? '1' : '0';
        if (e) {
            b |= 1 << i;
        }
    }

    vector<op> ops(m);
    for (int i = 0; i < m; i++) {
        cin >> ops[i].a >> ops[i].b;
        ops[i].a--;
        ops[i].b--;
        if (ops[i].a > ops[i].b) {
            swap(ops[i].a, ops[i].b);
        }
    }
    
    set<string> ress;
    ress.insert(s);
    set<unsigned long long> resb;
    resb.insert(b);
    
    if (n < 60) {
        cout << compute(resb, ops) << endl;
    }
    else {
        cout << compute(ress, ops) << endl;
    }
    
    return 0;
}