#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<long long> vec[200005];
map<long long, long long> mp;
long long d[200005], tmp[2], son[200005], ans[200005], v[200005], n;
void dfs1(long long u, long long fa) {
  d[u] = d[fa] + 1;
  tmp[d[u] % 2]++;
  son[u] = 1;
  for (long long i = 0; i < vec[u].size(); i++) {
    long long v = vec[u][i];
    if (v == fa) continue;
    dfs1(v, u);
    son[u] += son[v];
  }
}
void add(long long u, long long fa) {
  mp[d[u] % 2]++;
  for (long long i = 0; i < vec[u].size(); i++) {
    long long v = vec[u][i];
    if (v == fa) continue;
    add(v, u);
  }
}
void dfs2(long long u, long long fa) {
  long long bc = 0;
  for (long long i = 0; i < vec[u].size(); i++) {
    long long v = vec[u][i];
    if (v == fa) continue;
    if (!bc || son[bc] < son[v]) bc = v;
  }
  for (long long i = 0; i < vec[u].size(); i++) {
    long long v = vec[u][i];
    if (v == fa || v == bc) continue;
    dfs2(v, u);
    ans[u] = ans[u] + mp[d[u] % 2] * (son[1] - son[v]);
    ans[u] = ans[u] - mp[(d[u] % 2 + 1) % 2] * (son[1] - son[v]);
    mp.clear();
  }
  if (bc) dfs2(bc, u);
  ans[u] = ans[u] + mp[d[u] % 2] * (son[1] - son[bc]);
  ans[u] = ans[u] - mp[(d[u] % 2 + 1) % 2] * (son[1] - son[bc]);
  for (long long i = 0; i < vec[u].size(); i++) {
    long long v = vec[u][i];
    if (v == fa || v == bc) continue;
    add(v, u);
  }
  mp[d[u] % 2]++;
  ans[u] = ans[u] + son[1] - 1;
  ans[u] = ans[u] + (tmp[d[u] % 2] - mp[d[u] % 2]) * son[u];
  ans[u] = ans[u] - (tmp[(d[u] % 2 + 1) % 2] - mp[(d[u] % 2 + 1) % 2]) * son[u];
}
int main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &v[i]);
  }
  for (long long i = 1; i < n; i++) {
    long long u, v;
    scanf("%lld%lld", &u, &v);
    vec[u].push_back(v);
    vec[v].push_back(u);
  }
  memset(son, 0, sizeof(son));
  memset(ans, 0, sizeof(ans));
  memset(d, 0, sizeof(d));
  dfs1(1, 0);
  dfs2(1, 0);
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    while (ans[i] < 0) ans[i] += mod;
    ans[i] %= mod;
    while (v[i] < 0) v[i] += mod;
    v[i] %= mod;
    sum = (sum + ans[i] * v[i]) % mod;
    sum = (sum + v[i] + mod) % mod;
  }
  cout << sum << endl;
  return 0;
}
