#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200005;
vector<int> val;
int cmp[MAX_N];
vector<int> G[MAX_N];
int cnt[MAX_N][2];
int al[2];
int ans;
long long add(long long x, long long y) { return (x + y) % 1000000007; }
long long sub(long long x, long long y) {
  return (x + 1000000007 - y) % 1000000007;
}
long long mul(long long x, long long y) { return x * y % 1000000007; }
void color(int u, int p, int kind) {
  cmp[u] = kind;
  al[kind]++;
  for (auto&(v) : (G[u])) {
    if (v != p) {
      color(v, u, kind ^ 1);
    }
  }
}
void dfs(int u, int p) {
  cnt[u][cmp[u]] = 1;
  int sm = 0;
  for (auto&(v) : (G[u])) {
    if (v != p) {
      dfs(v, u);
      for (int k = 0; k < (int)(2); ++k) {
        cnt[u][k] += cnt[v][k];
        sm += cnt[v][k];
      }
    }
  }
  for (auto&(v) : (G[u])) {
    if (v != p) {
      ans = add(ans, mul(mul(sub(cnt[v][cmp[u]], cnt[v][cmp[u] ^ 1]),
                             sm - cnt[v][0] - cnt[v][1]),
                         val[u]));
      ans = add(ans, mul(sub(cnt[v][cmp[u]], cnt[v][cmp[u] ^ 1]), val[u]));
      ans = add(ans, mul(sub(cnt[v][cmp[u]], cnt[v][cmp[u] ^ 1]),
                         mul(val[u], al[cmp[u]] - cnt[u][cmp[u]] +
                                         al[cmp[u] ^ 1] - cnt[u][cmp[u] ^ 1])));
    }
  }
  ans = add(ans, mul(sub(al[cmp[u]] - cnt[u][cmp[u]],
                         al[cmp[u] ^ 1] - cnt[u][cmp[u] ^ 1]),
                     val[u]));
  ans = add(ans, mul(sub(al[cmp[u]] - cnt[u][cmp[u]],
                         al[cmp[u] ^ 1] - cnt[u][cmp[u] ^ 1]),
                     mul(val[u], cnt[u][0] + cnt[u][1] - 1)));
  ans = add(ans, mul(al[cmp[u]] - cnt[u][cmp[u]] + al[cmp[u] ^ 1] -
                         cnt[u][cmp[u] ^ 1],
                     val[u]));
  ans = add(ans, mul(cnt[u][0] + cnt[u][1], val[u]));
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  val.resize(n);
  for (int i = 0; i < (int)(n); ++i) {
    cin >> val[i];
    val[i] = (val[i] + 1000000007) % 1000000007;
  }
  for (int i = 0; i < (int)(n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1), G[b - 1].push_back(a - 1);
  }
  color(0, -1, 0);
  dfs(0, -1);
  cout << ans << "\n";
  return 0;
}
