#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
int sub(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
int mul(int x, int y) { return 1LL * x * y % mod; }
int n, a[maxn];
vector<int> g[maxn];
int sz[maxn], dp[maxn][2], f[maxn][2];
void dfs1(int u, int fa) {
  sz[u]++;
  for (auto v : g[u]) {
    if (v == fa) continue;
    dfs1(v, u);
    sz[u] += sz[v];
    f[u][0] = add(f[u][0], f[v][1]);
    f[u][1] = add(f[u][1], f[v][0]);
  }
  f[u][0] = add(f[u][0], mul(sz[u], a[u]));
}
long long ans = 0;
void dfs2(int u, int fa) {
  ans = add(ans, sub(f[u][0], f[u][1]));
  for (auto v : g[u]) {
    if (v == fa) continue;
    int sz1 = sz[v], sz0 = sz[u];
    int f1 = f[v][1], f0 = f[v][0], ff1 = f[u][1], ff0 = f[u][0];
    sz[u] -= sz[v];
    sz[v] += sz[u];
    f[u][0] = sub(f[u][0], f[v][1]);
    f[u][1] = sub(f[u][1], f[v][0]);
    f[u][0] = sub(f[u][0], mul(sz1, a[u]));
    f[v][1] = add(f[u][0], f[v][1]);
    f[v][0] = add(f[u][1], f[v][0]);
    f[v][0] = add(f[v][0], mul(sz[u], a[v]));
    dfs2(v, u);
    sz[u] = sz0, sz[v] = sz1;
    f[v][1] = f1, f[v][0] = f0;
    f[u][1] = ff1, f[u][0] = ff0;
  }
}
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 = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  printf("%d\n", ans);
  return 0;
}
