#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5, P = 1e9 + 7;
int n, val[M];
int head[M], asdf;
struct edge {
  int to, nxt;
} G[M * 2];
void add_edge(int a, int b) {
  G[++asdf].to = b;
  G[asdf].nxt = head[a];
  head[a] = asdf;
}
int Md(int x) { return (x % P + P) % P; }
bool mark[M];
int sz[M], son[M], que_len, que[M];
void get_root(int x, int f) {
  sz[x] = 1;
  son[x] = 0;
  que[++que_len] = x;
  for (int i = head[x]; i; i = G[i].nxt) {
    int y = G[i].to;
    if (y == f || mark[y]) continue;
    get_root(y, x);
    sz[x] += sz[y];
    if (sz[y] > son[x]) son[x] = sz[y];
  }
}
int ans, sum[2], tot[2];
int dis[M], cnt[M];
void get_ans(int x, int f) {
  cnt[x] = cnt[f] * (-1);
  dis[x] = Md(val[x] - dis[f]);
  if (cnt[x] == 1) {
    ans = Md(ans + 2ll * dis[x] % P);
    ans = Md(1ll * dis[x] * tot[1] % P + ans);
    ans = Md(-sum[1] + ans);
    ans = Md(1ll * dis[x] * tot[1] % P + ans);
    ans = Md(-sum[1] + ans);
  } else {
    ans = Md(1ll * dis[x] * tot[0] % P + ans);
    ans = Md(sum[0] + ans);
    ans = Md(1ll * dis[x] * tot[0] % P + ans);
    ans = Md(sum[0] + ans);
  }
  for (int i = head[x]; i; i = G[i].nxt) {
    int y = G[i].to;
    if (y == f || mark[y]) continue;
    get_ans(y, x);
  }
}
void get_dis(int x, int f) {
  cnt[x] = cnt[f] * (-1);
  dis[x] = Md(dis[f] + val[x] * cnt[x]);
  if (cnt[x] == 1) {
    sum[0] = Md(sum[0] + dis[x]);
    tot[0]++;
    if (tot[0] >= P) tot[0] -= P;
  } else {
    sum[1] = Md(sum[1] + dis[x]);
    tot[1]++;
    if (tot[1] >= P) tot[1] -= P;
  }
  for (int i = head[x]; i; i = G[i].nxt) {
    int y = G[i].to;
    if (y == f || mark[y]) continue;
    get_dis(y, x);
  }
}
void solve(int x) {
  que_len = 0;
  get_root(x, x);
  for (int i = 1; i <= que_len; i++) {
    son[que[i]] = max(son[que[i]], que_len - sz[que[i]]);
    if (son[que[i]] < son[x]) x = que[i];
  }
  mark[x] = 1;
  sum[0] = sum[1] = 0;
  tot[0] = tot[1] = 0;
  for (int i = head[x]; i; i = G[i].nxt) {
    int y = G[i].to;
    if (mark[y]) continue;
    cnt[x] = 1, dis[x] = val[x];
    get_ans(y, x);
    cnt[x] = -1, dis[x] = 0;
    get_dis(y, x);
  }
  for (int i = head[x]; i; i = G[i].nxt) {
    int y = G[i].to;
    if (mark[y]) continue;
    solve(y);
  }
}
int main() {
  int a, b;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
    ans = (ans + val[i]) % P;
  }
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &a, &b);
    add_edge(a, b);
    add_edge(b, a);
  }
  solve(1);
  printf("%d\n", ans);
  return 0;
}
