#include <bits/stdc++.h>
const int N = 2e5 + 5, mod = 1e9 + 7;
int n, a[N], nxt[N << 1], head[N], to[N << 1], cnt, ans, f[N], g[N], uf[N],
    ug[N], siz[N];
int read() {
  int x = 0, f = 1;
  char s;
  while ((s = getchar()) > '9' || s < '0')
    if (s == '-') f = -1;
  while (s >= '0' && s <= '9')
    x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();
  return x * f;
}
void addEdge(const int u, const int v) {
  nxt[++cnt] = head[u], to[cnt] = v, head[u] = cnt;
}
int inc(int x, const int y) {
  x += y;
  if (x >= mod) return x - mod;
  if (x < 0) return x + mod;
  return x;
}
void DP1(const int u, const int fa) {
  siz[u] = f[u] = 1;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa) continue;
    DP1(v, u);
    f[u] += g[v], g[u] += f[v], siz[u] += siz[v];
  }
  ans = inc(ans, 1ll * a[u] * (f[u] - g[u]) % mod * (n - siz[u] + 1) % mod);
  ans = inc(ans, 1ll * a[u] * (siz[u] - 1) % mod);
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa)
      ans = inc(ans, 1ll * a[u] * (g[to[i]] - f[to[i]]) % mod *
                         (siz[u] - siz[to[i]] - 1) % mod);
}
void DP2(const int u, const int fa) {
  uf[u] = ug[fa] + g[fa] - f[u];
  ug[u] = uf[fa] + f[fa] - g[u];
  ans = inc(ans, 1ll * a[u] * (uf[u] - ug[u]) % mod * siz[u] % mod);
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) DP2(to[i], u);
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  int u, v;
  for (int i = 1; i < n; ++i) {
    u = read(), v = read();
    addEdge(u, v), addEdge(v, u);
  }
  DP1(1, 0);
  uf[0] = g[1], ug[0] = f[1];
  DP2(1, 0);
  printf("%d\n", ans);
  return 0;
}
