#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5, mod = 1e9 + 7;
int dp[maxn + 5], up[maxn + 5], sz[maxn + 5];
vector<int> g[maxn + 5];
int a[maxn + 5];
int n;
void ins(int &a, int b) { a = (a + b) % mod; }
void dfs(int k, int fa) {
  sz[k] = 1;
  for (auto u : g[k]) {
    if (u == fa) continue;
    dfs(u, k);
    sz[k] += sz[u];
    ins(dp[k], dp[u]);
  }
  dp[k] = mod - dp[k];
  ins(dp[k], 1LL * a[k] * sz[k] % mod);
}
void dfs1(int k, int fa) {
  for (auto u : g[k]) {
    if (u == fa) continue;
    up[u] = (1LL * a[u] * (n - sz[u]) % mod -
             (1LL * up[k] + dp[k] - (1LL * a[k] * sz[u] % mod - dp[u]))) %
            mod;
    if (up[u] < 0) up[u] += mod;
    dfs1(u, k);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] < 0) a[i] += mod;
  }
  for (int i = 2; i <= n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  dfs1(1, 0);
  int ans = 0;
  for (int i = 1; i <= n; ++i) ins(ans, dp[i]), ins(ans, up[i]);
  printf("%d\n", ans);
  return 0;
}
