#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 7;
long long n;
vector<long long> g[maxn];
long long a[maxn], dp[3][2][maxn], num[2][2][maxn];
void dfs1(long long u, long long fa) {
  dp[0][1][u] = a[u];
  num[0][1][u] = 1;
  for (long long i = 0; i < g[u].size(); i++) {
    long long v = g[u][i];
    if (v == fa) continue;
    dfs1(v, u);
    num[0][0][u] = (num[0][0][u] + num[0][1][v]) % mod;
    num[0][1][u] = (num[0][1][u] + num[0][0][v]) % mod;
    dp[0][1][u] = (dp[0][1][u] + a[u] * num[0][0][v] + dp[0][0][v] + mod) % mod;
    ;
    dp[0][0][u] = (dp[0][0][u] - a[u] * num[0][1][v] + dp[0][1][v] + mod) % mod;
  }
}
void dfs2(long long u, long long fa) {
  if (fa) {
    dp[1][0][u] = (dp[1][1][fa] - a[fa] * num[0][0][u] -
                   a[u] * (num[1][1][fa] - num[0][0][u]) + mod) %
                  mod;
    dp[1][1][u] = (dp[1][0][fa] + a[fa] * num[0][1][u] +
                   a[u] * (num[1][0][fa] - num[0][1][u]) + mod) %
                  mod;
    num[1][0][u] = num[1][1][fa];
    num[1][1][u] = num[1][0][fa];
  } else {
    dp[1][0][u] = dp[0][0][u];
    dp[1][1][u] = dp[0][1][u];
    num[1][0][u] = num[0][0][u];
    num[1][1][u] = num[0][1][u];
  }
  for (long long i = 0; i < g[u].size(); i++) {
    long long v = g[u][i];
    if (v == fa) continue;
    dfs2(v, u);
  }
}
int main() {
  memset(dp, 0, sizeof(dp));
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  long long u, v;
  for (long long i = 1; i < n; i++) {
    scanf("%lld%lld", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans = (ans + (dp[1][1][i] + mod) % mod + mod) % mod;
  }
  printf("%lld", ans);
}
