#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
const int N = 500000, mo = 1e9 + 7;
int n, head[N], v[N], to[N], nxt[N], edgenum;
void add(int u, int v) {
  to[++edgenum] = v;
  nxt[edgenum] = head[u];
  head[u] = edgenum;
}
int size[N], tot, f[N], dep[N];
long long ans;
void dfs(int u, int fa, int depth) {
  size[u] = 1;
  dep[u] = depth;
  f[u] = (dep[u] == 1) ? 1 : -1;
  for (int i = head[u]; i != 0; i = nxt[i])
    if (to[i] != fa)
      dfs(to[i], u, depth ^ 1), size[u] += size[to[i]], f[u] += f[to[i]];
}
long long CNT[N];
void dfs1(int u, int fa) {
  int cnt = tot - (dep[u] == 1 ? 1 : -1);
  for (int i = head[u]; i != 0; i = nxt[i])
    if (to[i] != fa) {
      dfs1(to[i], u);
      int now = f[to[i]];
      cnt -= now;
      ans += 1LL * (dep[u] == 1 ? 1 : -1) * now * (n - size[to[i]]) % mo *
             v[u] % mo;
      CNT[u] += 1LL * (dep[u] == 1 ? 1 : -1) * now * (n - size[to[i]]) % mo;
    }
  CNT[u] += 1LL * (dep[u] == 1 ? 1 : -1) * cnt * (size[u]) % mo + n;
  ans += 1LL * (dep[u] == 1 ? 1 : -1) * cnt * (size[u]) % mo * v[u] % mo;
  ans += 1LL * n * v[u] % mo;
}
int main() {
  read(n);
  for (register int i = 1; i <= n; i++) read(v[i]);
  for (register int i = 2; i <= n; i++) {
    int x, y;
    read(x);
    read(y);
    add(x, y);
    add(y, x);
  }
  dfs(1, 0, 0);
  tot = f[1];
  dfs1(1, 0);
  cout << ((ans % mo + mo) % mo);
  return 0;
}
