#include <bits/stdc++.h>
using namespace std;
int fa[200005], d[200005], a[200005];
long long v[200005], f[200005][5], g[200005][5], ans, n, siz[200005];
vector<int> G[200005];
bool cmp(int x, int y) { return d[x] < d[y]; }
void dfs(int x, int father) {
  fa[x] = father, siz[x] = 1, d[x] = d[father] + 1, f[x][0] = 1;
  for (int i = 0; i < G[x].size(); i++) {
    int tmp = G[x][i];
    if (tmp != father) {
      dfs(tmp, x);
      f[x][1] += f[tmp][0], f[x][0] += f[tmp][1];
      siz[x] += siz[tmp];
    }
  }
  for (int i = 0; i < G[x].size(); i++) {
    int tmp = G[x][i];
    if (tmp != father) {
      ans = (ans +
             (f[tmp][1] - f[tmp][0]) % 1000000007 * (siz[x] - siz[tmp] - 1) %
                 1000000007 * v[x] % 1000000007 +
             1000000007) %
            1000000007;
    }
  }
  ans = (ans + (siz[x] - 1) * v[x] % 1000000007 + 1000000007) % 1000000007;
  ans = (ans +
         (f[x][0] - f[x][1]) % 1000000007 * (n - siz[x] + 1) % 1000000007 *
             v[x] % 1000000007 +
         1000000007) %
        1000000007;
}
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &v[i]);
    a[i] = i;
  }
  for (int i = 1; i < n; i++) {
    int u, w;
    scanf("%d %d", &u, &w);
    G[u].push_back(w);
    G[w].push_back(u);
  }
  dfs(1, 0);
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 2; i <= n; i++) {
    int u = a[i];
    g[u][0] = g[fa[u]][1] + f[fa[u]][1] - f[u][0];
    g[u][1] = g[fa[u]][0] + f[fa[u]][0] - f[u][1];
    ans = (ans +
           (g[u][0] - g[u][1]) % 1000000007 * siz[u] % 1000000007 * v[u] %
               1000000007 +
           1000000007) %
          1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}
