#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  x *= f;
}
int n;
int v[200010];
vector<int> e[200010];
int d[200010], sz[2][200010], fa[200010];
int P = 1000000007, ans;
void dfs(int x, int f, int dd) {
  d[x] = dd;
  fa[x] = f;
  sz[dd][x]++;
  int si = e[x].size();
  for (int i = 0; i < si; ++i) {
    int u = e[x][i];
    if (u != f) {
      dfs(u, x, dd ^ 1);
      sz[0][x] += sz[0][u];
      sz[1][x] += sz[1][u];
    }
  }
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) read(v[i]);
  for (int i = 1; i <= n - 1; ++i) {
    int x, y;
    read(x);
    read(y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1, 0, 0);
  for (int x = 1; x <= n; ++x) {
    int si = e[x].size();
    long long cnt = n;
    for (int i = 0; i < si; ++i) {
      int u = e[x][i], hv[2];
      if (u == fa[x])
        hv[0] = sz[0][1] - sz[0][x], hv[1] = sz[1][1] - sz[1][x];
      else
        hv[0] = sz[0][u], hv[1] = sz[1][u];
      cnt = (cnt + 1ll * hv[d[x]] * (n - hv[0] - hv[1])) % P;
      cnt = (cnt - 1ll * hv[d[x] ^ 1] * (n - hv[0] - hv[1])) % P;
      if (cnt < 0) cnt += P;
    }
    ans = (1ll * cnt * v[x] + ans) % P;
    if (ans < 0) ans += P;
  }
  cout << ans << endl;
  return 0;
}
