#include <bits/stdc++.h>
using namespace std;
const long double PI = atan(1.0) * 4;
const int64_t INF = 8e18;
const int32_t LOG = 21;
const long long int MOD = 1e9 + 7;
long long int a[200005];
long long int siz[200005];
long long int cnt[200005][2];
long long int dp[200005][2];
vector<long long int> v[200005];
long long int ans = 0;
long long int n;
void dfs(long long int i, long long int prev) {
  cnt[i][1] = 1;
  siz[i]++;
  for (auto it : v[i]) {
    if (it != prev) {
      dfs(it, i);
      siz[i] += siz[it];
      cnt[i][0] += cnt[it][1];
      cnt[i][1] += cnt[it][0];
    }
  }
}
void dfs1(long long int i, long long int prev) {
  dp[i][1] = 1;
  long long int toAdd = 0;
  for (auto it : v[i]) {
    if (it != prev) {
      dp[i][0] += cnt[it][1];
      dp[i][1] += cnt[it][0];
      dp[i][0] %= MOD;
      dp[i][1] %= MOD;
      toAdd += (((cnt[it][0] - cnt[it][1] + MOD) * (n - siz[it])) % MOD) *
               (a[i] + MOD);
      toAdd %= MOD;
    }
  }
  if (prev != -1) {
    toAdd += (((dp[prev][0] - cnt[i][1] - dp[prev][1] + cnt[i][0] + 2 * MOD) *
               (siz[i])) %
              MOD) *
             (a[i] + MOD);
    dp[i][0] += (dp[prev][1] - cnt[i][0] + MOD);
    dp[i][1] += (dp[prev][0] - cnt[i][1] + MOD);
    dp[i][0] %= MOD;
    dp[i][1] %= MOD;
    toAdd %= MOD;
  }
  toAdd += n * (a[i] + MOD);
  toAdd %= MOD;
  ans += toAdd;
  while (ans >= MOD) ans -= MOD;
  for (auto it : v[i]) {
    if (it != prev) dfs1(it, i);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int tests = 1;
  for (long long int ii = 0; ii < tests; ii++) {
    cin >> n;
    for (long long int i = 1; i < n + 1; i++) cin >> a[i];
    for (long long int i = 1; i < n; i++) {
      long long int x, y;
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
  }
  dfs(1, -1);
  dfs1(1, -1);
  cout << ans << '\n';
  return 0;
}
