#include <bits/stdc++.h>
using namespace std;
const int N = 202020, P = 1e9 + 7;
int n;
int a[N], par[N], cnt[2][N], c[2][N];
long long ans;
vector<int> g[N];
void upd(long long &a, long long b) {
  if (b < 0) b += P;
  a += b;
  if (a >= P) a -= P;
}
void dfs(int u, int fa) {
  cnt[0][u] = 1;
  cnt[1][u] = 0;
  par[u] = fa;
  for (int i = (0); i < ((int)g[u].size()); i++) {
    int v = g[u][i];
    if (v == fa) continue;
    dfs(v, u);
    cnt[0][u] += cnt[1][v];
    cnt[1][u] += cnt[0][v];
  }
}
void dfs2(int u) {
  if (par[u]) {
    c[0][u] = c[1][par[u]];
    c[1][u] = c[0][par[u]];
  } else {
    c[0][u] = cnt[0][u];
    c[1][u] = cnt[1][u];
  }
  for (int i = (0); i < ((int)g[u].size()); i++) {
    int v = g[u][i];
    if (v == par[u]) continue;
    dfs2(v);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); i++) {
    scanf("%d", a + i);
    if (a[i] < 0) a[i] += P;
  }
  for (int i = (1); i < (n); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  dfs2(1);
  for (int i = (1); i < (n + 1); i++) {
    long long pre = ans;
    int c0 = c[0][i], c1 = c[1][i];
    upd(ans, 1ll * c0 * c0 % P * a[i] % P);
    upd(ans, -1ll * c1 * c1 % P * a[i] % P);
    if (par[i]) {
      c0 = c[0][par[i]] - cnt[1][i];
      c1 = c[1][par[i]] - cnt[0][i];
      upd(ans, 1ll * c0 * c0 % P * a[i] % P);
      upd(ans, -1ll * c1 * c1 % P * a[i] % P);
    }
    for (int j = (0); j < ((int)g[i].size()); j++) {
      int v = g[i][j];
      if (v != par[i]) {
        c0 = cnt[0][v];
        c1 = cnt[1][v];
        upd(ans, 1ll * c0 * c0 % P * a[i] % P);
        upd(ans, -1ll * c1 * c1 % P * a[i] % P);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
