#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 9;
const long long M = 1000000007;
vector<int> G[N];
int a[N];
long long s[N][3];
void dfs(int u, int p) {
  for (int v : G[u])
    if (v != p) {
      dfs(v, u);
      s[u][0] += s[v][1];
      s[u][1] += s[v][0];
      s[u][2] += s[v][2];
    }
  ++s[u][2];
  s[u][1] %= M;
  s[u][0] = (s[u][0] + a[u] * s[u][2]) % M;
}
long long ans;
void dfs2(int u, int p, long long s0, long long s1, long long s2) {
  ans = (ans + s0 + s[u][0] - s1 - s[u][1] + a[u] * s2) % M;
  for (int v : G[u])
    if (v != p) {
      dfs2(v, u, (s1 + s[u][1] - s[v][0]) % M,
           (s0 + s[u][0] - s[v][1] + a[u] * (s2 - s[v][2])) % M,
           s2 + s[u][2] - s[v][2]);
    }
}
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  dfs2(1, 0, 0, 0, 0);
  printf("%lld\n", (ans + M) % M);
}
int main() {
  int T = 1;
  while (T--) solve();
  return 0;
}
