#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const long long MOD = 1e9 + 7;
const int N = 2e5 + 7;
vector<int> g[N];
int val[N];
int n;
int cnt[N];
int dp[N][2];
int up[N][2];
long long ans = 0;
void dfs(int u, int f) {
  dp[u][0] = 1;
  dp[u][1] = 0;
  cnt[u] = 1;
  for (auto v : g[u])
    if (v != f) {
      dfs(v, u);
      dp[u][0] += dp[v][1];
      dp[u][1] += dp[v][0];
      cnt[u] += cnt[v];
    }
}
void dfs2(int u, int f) {
  for (auto v : g[u])
    if (v != f) {
      up[v][0] = up[u][1] + dp[u][1] - dp[v][0];
      up[v][1] = up[u][0] + dp[u][0] - dp[v][1];
      dfs2(v, u);
    }
}
void dfs3(int u, int f) {
  ans += 1LL * val[u] * n % MOD;
  ans %= MOD;
  for (auto v : g[u])
    if (v != f) {
      ans -= 1LL * val[u] * dp[v][0] % MOD * (n - cnt[v]) % MOD;
      ans += 1LL * val[u] * dp[v][1] % MOD * (n - cnt[v]) % MOD;
      ans = (ans % MOD + MOD) % MOD;
      dfs3(v, u);
    }
  ans -= 1LL * val[u] * up[u][1] % MOD * cnt[u] % MOD;
  ans += 1LL * val[u] * up[u][0] % MOD * cnt[u] % MOD;
  ans = (ans % MOD + MOD) % MOD;
}
int main() {
  scanf("%d", &n);
  for (int i = int(1); i <= int(n); ++i) scanf("%d", val + i);
  int u, v;
  for (int i = int(1); i <= int(n - 1); ++i) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  dfs2(1, 0);
  dfs3(1, 0);
  cout << ans << endl;
}
