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
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>

#define PI pair<int, int>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

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

    vector<int> configs(10000000);
    unordered_map<int, bool> seen;
    vector<PI> edges(m);

    int x;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x;
        configs[0] += (x << i);
    }
    seen[configs[0]] = true;

    for (int i = 0; i < m; ++i)
    {
        cin >> edges[i].first >> edges[i].second;
    }

    int k = 1;
    for (int i = 0; i < k; ++i)
    {
        x = configs[i];
        for (auto &[a, b] : edges)
        {
            int filter = (1 << a) | (1 << b);
            if (__builtin_popcount(x & filter) & 1 || seen[x ^ filter]) continue;
            seen[x ^ filter] = true;
            configs[k++] = x ^ filter;
        }
    }

    cout << k;
}