#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n;
long long dp[200010][4], cnt[200010][4], V[200010];
vector<int> adj[200010];
void f(int p, int u) {
  for (int v : adj[u])
    if (v != p) f(u, v);
  dp[u][0] = V[u];
  dp[u][1] = 0;
  dp[u][2] = V[u];
  dp[u][3] = 0;
  cnt[u][0] = 1;
  cnt[u][1] = 0;
  cnt[u][2] = 1;
  cnt[u][3] = 0;
  int child = 1;
  for (int v : adj[u]) {
    if (v == p) continue;
    if (child > 0) {
      dp[u][3] = (dp[u][3] + dp[u][1] * cnt[v][2] % MOD +
                  dp[v][2] * cnt[u][1] % MOD + MOD) %
                 MOD;
      cnt[u][3] = (cnt[u][3] + cnt[u][1] * cnt[v][2] % MOD) % MOD;
      dp[u][3] =
          (dp[u][3] + (dp[u][0] - V[u] % MOD + MOD) % MOD * cnt[v][2] % MOD -
           dp[v][2] * (cnt[u][0] - 1) % MOD + MOD) %
          MOD;
      cnt[u][3] = (cnt[u][3] + cnt[u][0] * cnt[v][2] % MOD) % MOD;
      dp[u][3] = (dp[u][3] + dp[v][0] * (cnt[u][2] - 1) % MOD -
                  (dp[u][2] - V[u]) * cnt[v][0] % MOD + MOD) %
                 MOD;
      cnt[u][3] = (cnt[u][3] + cnt[u][2] * cnt[v][0] % MOD) % MOD;
      dp[u][3] = (dp[u][3] + dp[v][1] * (cnt[u][2] - 1) % MOD +
                  (dp[u][2] - V[u]) * cnt[v][1] % MOD + MOD) %
                 MOD;
      cnt[u][3] = (cnt[u][3] + cnt[u][2] * cnt[v][1] % MOD) % MOD;
    }
    dp[u][0] = (dp[u][0] + dp[v][1] + cnt[v][1] * V[u]) % MOD;
    cnt[u][0] = (cnt[u][0] + cnt[v][1]) % MOD;
    dp[u][1] = (dp[u][1] + dp[v][0] - cnt[v][0] * V[u] % MOD + MOD) % MOD;
    cnt[u][1] = (cnt[u][1] + cnt[v][0]) % MOD;
    dp[u][2] = (dp[u][2] - dp[v][2] + cnt[v][2] * V[u] % MOD + MOD) % MOD;
    cnt[u][2] = (cnt[u][2] + cnt[v][2]) % MOD;
    child++;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", V + i);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  f(0, 1);
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    res = (res + dp[i][0] + dp[i][1] + dp[i][2] + dp[i][3] - V[i] % MOD + MOD) %
          MOD;
  }
  printf("%lld", res);
  return 0;
}
