#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 1e5 + 5;
const int modu = 1e9 + 7;
inline void add(ll &x,ll y){
x = (x + y) % modu;
}
int a[maxn];
ll dp[maxn][2],XOR[maxn];
vector <int> vec[maxn];
void input(int n){
for (int i = 1 ; i <= n ; i++) cin >> a[i];
for (int i = 1 ; i < n ; i++){
int u,v;
cin >> u >> v;
vec[u].push_back(v);
vec[v].push_back(u);
}
}
void prepare_dfs(int u,int par){
XOR[u] = a[u];
for (int v : vec[u])
if (v != par){
prepare_dfs(v,u);
XOR[u] ^= XOR[v];
}
}
void solve(int u,int par,int x){
for (int v : vec[u])
if (v != par)
solve(v,u,x);
ll f[2];
f[0] = f[1] = 0;
for (int v : vec[u])
if (v != par){
f[0] = (dp[u][0] * dp[v][0] + dp[u][1] * dp[v][1]) % modu;
f[1] = (dp[u][0] * dp[v][1] + dp[u][1] * dp[v][0]) % modu;
add(dp[u][0],f[0]);
add(dp[u][1],f[1]);
add(dp[u][0],dp[v][0]);
add(dp[u][1],dp[v][1]);
}
f[0] = dp[u][0];
f[1] = dp[u][1];
if (u != 1 && XOR[u] == x) add(dp[u][1],f[0]);
if (u != 1 && XOR[u] == 0) add(dp[u][0],f[1]);
if (u != 1 && XOR[u] == x) add(dp[u][1],1);
}
void solve_0(int u,int par,ll &res){
if (!XOR[u] && u != 1) res = res * 2 % modu;
for (int v : vec[u])
if (v != par)
solve_0(v,u,res);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,x;
cin >> n >> x;
input(n);
prepare_dfs(1,0);
if (x == 0){
ll res1 = 1;
solve_0(1,0,res1);
cout << res1;
return 0;
}
solve(1,0,x);
if (XOR[1] != 0 && XOR[1] != x){
cout << 0;
return 0;
}
int st = (XOR[1] == x);
cout << (dp[1][1 - st] + st) % modu;
return 0;
}
I2luY2x1ZGU8Yml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