#include <bits/stdc++.h>
#define TASK "TREEXOR"
#define int long long
#define MOD 1000000007
using namespace std;
int n, x;
int a[100005], xo[100005], res = 0;
vector <int> adj[100005];
void dfs(int u, int up) {
xo[u] = a[u];
for (int v : adj[u]) {
if (v != up) {
dfs(v, u);
xo[u] ^= xo[v];
}
}
if (xo[u] == x) {
res = (res == 0) ? 1 : res * 2 % MOD;
}
}
signed main() {
if (fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
cout << res;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgVEFTSyAiVFJFRVhPUiIKI2RlZmluZSBpbnQgbG9uZyBsb25nCiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbiwgeDsKaW50IGFbMTAwMDA1XSwgeG9bMTAwMDA1XSwgcmVzID0gMDsKdmVjdG9yIDxpbnQ+IGFkalsxMDAwMDVdOwoKdm9pZCBkZnMoaW50IHUsIGludCB1cCkgewogICAgeG9bdV0gPSBhW3VdOwogICAgZm9yIChpbnQgdiA6IGFkalt1XSkgewogICAgICAgIGlmICh2ICE9IHVwKSB7CiAgICAgICAgICAgIGRmcyh2LCB1KTsKICAgICAgICAgICAgeG9bdV0gXj0geG9bdl07CiAgICAgICAgfQogICAgfQogICAgaWYgKHhvW3VdID09IHgpIHsKICAgICAgICByZXMgPSAocmVzID09IDApID8gMSA6IHJlcyAqIDIgJSBNT0Q7CiAgICB9Cn0KCnNpZ25lZCBtYWluKCkgewogICAgaWYgKGZvcGVuKFRBU0siLmlucCIsICJyIikpIHsKICAgICAgICBmcmVvcGVuKFRBU0siLmlucCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4oVEFTSyIub3V0IiwgInciLCBzdGRvdXQpOwogICAgfQogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7CiAgICBjb3V0LnRpZSgwKTsKICAgIGNpbiA+PiBuID4+IHg7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgIH0KICAgIGZvciAoaW50IGkgPSAxOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgaW50IHUsIHY7CiAgICAgICAgY2luID4+IHUgPj4gdjsKICAgICAgICBhZGpbdV0ucHVzaF9iYWNrKHYpOwogICAgICAgIGFkalt2XS5wdXNoX2JhY2sodSk7CiAgICB9CiAgICBkZnMoMSwgMCk7CiAgICBjb3V0IDw8IHJlczsKfQo=