#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e6 + 7;
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = (long long)a * a % M)
    if (b & 1) ret = (long long)ret * a % M;
  return ret;
}
vector<int> edge[maxn];
long long A[maxn];
long long f[maxn][2], g[maxn][2];
long long dfs(int x, int fa) {
  f[x][1] = 0;
  f[x][0] = A[x];
  long long ret = f[x][0] % M;
  f[x][1] = 0;
  g[x][0] = 1;
  for (int v : edge[x])
    if (v != fa) {
      ret += dfs(v, x);
      (ret += g[x][0] * f[v][1] * 2) %= M;
      (ret += g[x][1] * f[v][0] * 2) %= M;
      (ret += g[v][0] * f[x][1] * 2) %= M;
      (ret += g[v][1] * f[x][0] * 2) %= M;
      (f[x][0] += f[v][1] + g[v][1] * A[x]) %= M;
      (f[x][1] += f[v][0] - g[v][0] * A[x]) %= M;
      g[x][0] += g[v][1];
      g[x][1] += g[v][0];
    }
  return ret;
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%I64d", &A[i]);
  for (i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  long long ans = dfs(1, 0);
  (ans += M) %= M;
  printf("%I64d\n", ans);
}
