#include <bits/stdc++.h>
using namespace std;
const long long p = 1e9 + 7;
long long n, a[200005], fa[200005], x, y, sz[200005], dp[200005][2], ans,
    g[200005][2];
vector<long long> v[200005];
void dfs(long long x, long long y) {
  fa[x] = y;
  sz[x]++;
  dp[x][0] = 1;
  for (long long i = 0; i < v[x].size(); i++) {
    long long h = v[x][i];
    if (h == y) continue;
    dfs(h, x);
    sz[x] += sz[h];
    dp[x][0] += dp[h][1];
    dp[x][1] += dp[h][0];
  }
  for (long long i = 0; i < v[x].size(); i++) {
    long long h = v[x][i];
    if (h == y) continue;
    long long rest = sz[x] - sz[h], fl = dp[h][1] - dp[h][0];
    ans = (ans + fl * rest % p * a[x]) % p;
    rest = n - sz[x];
    ans = (ans + fl * rest % p * a[x]) % p;
  }
  ans = (ans + (n - sz[x]) * a[x]) % p;
}
void dfs2(long long x) {
  for (long long i = 0; i < v[x].size(); i++) {
    long long h = v[x][i];
    if (h == fa[x]) continue;
    g[h][0] = dp[x][1] - dp[h][0] + g[x][1] + 1;
    g[h][1] = dp[x][0] - dp[h][1] + g[x][0] - 1;
    dfs2(h);
  }
  long long fl = g[x][0] - g[x][1];
  ans = (ans + fl * sz[x] % p * a[x]) % p;
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i < n; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, 0);
  g[1][0] = 1;
  dfs2(1);
  printf("%lld", (ans + p) % p);
}
