#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N = 200000 + 10, MOD = 1e9 + 7;
int n, v[N];
int ans = 0;
vector<int> G[N];
int size[N][2];
void dfs_size(int x, int fa) {
  size[x][0] = 1;
  size[x][1] = 0;
  for (int v : G[x])
    if (v != fa) {
      dfs_size(v, x);
      size[x][0] += size[v][1];
      size[x][1] += size[v][0];
    }
}
inline int norm(int x) {
  if (x >= MOD || x <= -MOD) x %= MOD;
  if (x < 0) x += MOD;
  return x;
}
inline int add(int x, int y) {
  x = norm(x);
  y = norm(y);
  return (x + y) % MOD;
}
void dfs(int x, int fa, int up0, int up1, int up_size) {
  int sizer = size[x][0] + size[x][1];
  ans = add(ans, 1ll * (up0 + 1) * sizer % MOD * v[x] % MOD);
  ans = add(ans, -1ll * up1 * sizer % MOD * v[x] % MOD);
  ans = add(ans, 1ll * size[x][0] * (up_size + 1) % MOD * v[x] % MOD);
  ans = add(ans, -1ll * size[x][1] * (up_size + 1) % MOD * v[x] % MOD);
  ans = add(ans, -v[x]);
  for (int t : G[x])
    if (t != fa) {
      int sizet = size[t][0] + size[t][1];
      ans =
          add(ans, -1ll * size[t][0] * (sizer - sizet - 1) % MOD * v[x] % MOD);
      ans = add(ans, 1ll * size[t][1] * (sizer - sizet - 1) % MOD * v[x] % MOD);
    }
  for (int v : G[x])
    if (v != fa)
      dfs(v, x, up1 + size[x][1] - size[v][0], up0 + size[x][0] - size[v][1],
          up_size + sizer - size[v][0] - size[v][1]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs_size(1, -1);
  dfs(1, -1, 0, 0, 0);
  printf("%d\n", ans);
}
