#include <bits/stdc++.h>
using namespace std;
const int N = 200007, inf = 0x3f3f3f3f, M = 1000000007;
vector<int> edges[N];
pair<long long, long long> cnt[N];
long long a[N];
pair<long long, long long> dfs(int u, int prev) {
  long long par, imp;
  par = imp = 0;
  for (int v : edges[u]) {
    if (v == prev) continue;
    pair<long long, long long> aux = dfs(v, u);
    imp += aux.first;
    par += aux.second;
  }
  par++;
  cnt[u] = make_pair(par, imp);
  return cnt[u];
}
inline long long mul(long long a, long long b) { return (a % M * b % M) % M; }
long long solve(int u, int prev, int imp = 0) {
  long long tot = 0, aux = 0;
  long long par = cnt[1].first, impar = cnt[1].second;
  for (int v : edges[u]) {
    if (v == prev) continue;
    tot += solve(v, u, !imp);
    tot %= M;
    if (imp == 0) {
      aux += mul(a[u], mul(cnt[v].second, par - cnt[v].second) -
                           mul(cnt[v].first, impar - cnt[v].first) + M);
      par -= cnt[v].second;
      impar -= cnt[v].first;
    } else {
      aux += mul(a[u], mul(cnt[v].second, impar - cnt[v].second) -
                           mul(cnt[v].first, par - cnt[v].first) + M);
      par -= cnt[v].first;
      impar -= cnt[v].second;
    }
    aux %= M;
  }
  if (imp == 0) {
    aux += (a[u] * (cnt[1].first - cnt[u].first + M) % M) % M;
  } else
    aux += (a[u] * (cnt[1].second - cnt[u].first + M) % M) % M;
  aux %= M;
  tot += (2 * aux + a[u]) % M;
  tot %= M;
  return tot;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] = (a[i] + M) % M;
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  dfs(1, -1);
  cout << solve(1, -1) << endl;
}
