#include <bits/stdc++.h>
using namespace std;
const int mod = (int)(1e9) + 7;
int head[300005], v[300005 * 2], suc[300005 * 2], en = 1;
void addedge(int iu, int iv) {
  en++;
  v[en] = iv;
  suc[en] = head[iu];
  head[iu] = en;
}
long long V[300005], f[300005][2], g[300005][2];
long long ans;
void dfs1(int s, int par) {
  f[s][0] = g[s][0] = 0;
  f[s][1] = g[s][1] = 1;
  for (int i = head[s]; i; i = suc[i])
    if (v[i] != par) {
      dfs1(v[i], s);
      g[s][0] = (g[s][0] + (long long)f[s][0] * f[v[i]][1] % mod) % mod;
      g[s][1] = (g[s][1] + (long long)f[s][1] * f[v[i]][0] % mod) % mod;
      f[s][0] = (f[s][0] + f[v[i]][1]) % mod;
      f[s][1] = (f[s][1] + f[v[i]][0]) % mod;
    }
}
void dfs2(int s, int par, long long gp0, long long gp1) {
  ans = (ans +
         (long long)V[s] * (g[s][1] + (long long)f[s][1] * gp1 % mod) % mod) %
        mod;
  ans = (ans -
         (long long)V[s] * (g[s][0] + (long long)f[s][0] * gp0 % mod) % mod) %
        mod;
  ans = (ans % mod + mod) % mod;
  for (int i = head[s]; i; i = suc[i])
    if (v[i] != par) {
      dfs2(v[i], s, ((long long)gp1 + f[s][1] - f[v[i]][0]) % mod,
           ((long long)gp0 + f[s][0] - f[v[i]][1]) % mod);
    }
}
int main() {
  int i, j, k;
  int n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%I64d", V + i);
  }
  for (i = 1; i < n; i++) {
    scanf("%d%d", &j, &k);
    addedge(j, k);
    addedge(k, j);
  }
  dfs1(1, 0);
  dfs2(1, 0, 0, 0);
  ans = 2ll * ans % mod;
  for (i = 1; i <= n; i++) ans = (ans - V[i]) % mod;
  ans = (ans % mod + mod) % mod;
  printf("%I64d", ans);
  return 0;
}
