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
#include<bits/stdc++.h>      
using namespace std;
typedef long long ll;
const int P = 101;
const ll MLL = 1e18;
const ll LOG = 31;
const int N = 2e6;
const ll mod = 1e9 + 7;
ll ans = 1 , cur = 1;
vector<int> v;
vector<vector<int>> edges;
vector<int> nodes;
vector<bool> was;
unordered_map<string , int> pres;

struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        if (hash1 != hash2) {
            return hash1 ^ hash2;              
        }
          return hash1;
    }
};
unordered_map<pair<int , int> , int, hash_pair> mp;


void dfs(int i) {
	was[i] = true;
	for(int x : edges[i]) if(!was[x]) dfs(x);
	nodes.push_back(i);
}

void bfs() {
	
	string in = "";
    cur = 0;
    int n = nodes.size();
    queue<string> q;
	
	for(int i = 0; i < (int)nodes.size(); i++) in.push_back(char('0' + v[nodes[i]]));
	q.push(in);
	pres[in] = 1;
	
	while(q.size() > 0) {
		cur = (cur + 1) % mod;
		string comb = q.front();
		q.pop();
		for(int i = 0; i < n;i++) {
			for(int j = i; j < n; j++) {
				if(comb[i] == comb[j] && mp.find({nodes[i], nodes[j]}) != mp.end()){
					string w = comb;
					if(w[i] == '1') {
						w[i] = '0';
						w[j] = '0';
					}else {
						w[i] = '1';
						w[j] = '1';
					}
					if(pres.find(w) == pres.end()) {
						pres[w] = 1;
						q.push(w);
					}
				} 
			}
		}
	}
}

void sol(int ind) {
	cur = 1;
	nodes.clear();
	pres.clear();
	dfs(ind);
	bfs();
	ans = (ans * cur) % mod;
}

												
void solve() {
	
	int n, m;
	cin >> n >> m;
	v.resize(n);
	was.resize(n);
	edges.resize(n);
	for(int i = 0; i < n; i++) cin >> v[i];
	for(int i = 0; i < m; i++) {
		int a , b;
		cin >> a >> b;
		a--, b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
		mp[{a , b}] = 1;
		mp[{b , a}] = 1;
	}
	for(int i = 0; i < n;i++) {
		if(!was[i]) sol(i);
	}
	cout << ans <<endl;
}

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


    return 0;
}