#include <bits/stdc++.h>
using namespace std;
const int N = 200010, P = 1000000007;
long long sum[2], ans, tsum[2];
int root, total;
int a[N], h[N], siz[N], cnt[2], tcnt[2];
bool v[N];
vector<int> g[N];
void dfs1(int x, int tp) {
  siz[x] = 1;
  h[x] = 0;
  for (auto p : g[x])
    if (p != tp && !v[p]) {
      dfs1(p, x);
      siz[x] += siz[p];
      h[x] = max(h[x], siz[p]);
    }
  h[x] = max(h[x], total - siz[x]);
  if (!root || h[x] < h[root]) root = x;
}
void dfs2(int x, int tp, int len, long long val) {
  (tsum[len] += val) %= P;
  siz[x] = 1;
  tcnt[len]++;
  for (auto p : g[x])
    if (p != tp && !v[p]) {
      dfs2(p, x, len ^ 1, (val + (len ? (P - 1ll) : 1ll) * a[p] % P) % P);
      siz[x] += siz[p];
    }
}
void solve(int x) {
  v[x] = 1;
  sum[0] = sum[1] = cnt[0] = cnt[1] = 0;
  (ans += a[x]) %= P;
  for (auto p : g[x])
    if (!v[p]) {
      tsum[0] = tsum[1] = tcnt[0] = tcnt[1] = 0;
      dfs2(p, x, 1, a[p]);
      ans += 2ll * tcnt[0] * cnt[0] % P * a[x] % P +
             1ll * (P - 2) * sum[0] % P * tcnt[0] % P + P -
             2ll * tsum[0] * cnt[0] % P;
      ans += 1ll * (P - 2) * tcnt[1] % P * cnt[1] % P * a[x] % P +
             2ll * sum[1] * tcnt[1] % P + 2ll * tsum[1] * cnt[1] % P;
      ans += 1ll * (P - 2) * tsum[0] % P + 2ll * tcnt[0] * a[x] % P;
      ans %= P;
      (sum[0] += tsum[0]) %= P;
      (sum[1] += tsum[1]) %= P;
      cnt[0] += tcnt[0];
      cnt[1] += tcnt[1];
    }
  for (auto p : g[x])
    if (!v[p]) {
      root = 0, total = siz[p];
      dfs1(p, p);
      solve(root);
    }
}
int main() {
  int n;
  cin >> n;
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]), a[i] = (a[i] + P) % P;
  int x, y;
  for (int i = (2); i <= (n); i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  total = n, root = 0;
  dfs1(1, 1);
  solve(root);
  cout << ans << endl;
  return 0;
}
