#include <bits/stdc++.h>
using namespace std;
long long V[200007];
vector<long long> edg[200007];
long long even[200007], odd[200007];
void dfs1(long long u, long long p) {
  even[u] = 1;
  odd[u] = 0;
  for (long long v : edg[u]) {
    if (v == p) continue;
    dfs1(v, u);
    even[u] += odd[v];
    odd[u] += even[v];
  }
}
long long ans;
long long n;
void dfs2(long long u, long long p, long long upEven, long long upOdd) {
  long long total = even[u] + odd[u];
  long long pluss = 0;
  long long minuss = 0;
  for (long long v : edg[u]) {
    if (v == p) {
      ans = (ans + ((upOdd * V[u]) % 1000000007 * total) % 1000000007) %
            1000000007;
      ans = (ans - ((upEven * V[u]) % 1000000007 * total) % 1000000007) %
            1000000007;
      minuss += upEven * total;
      pluss += upOdd * total;
    } else {
      ans = (ans + ((odd[v] * V[u]) % 1000000007 * (n - odd[v] - even[v])) %
                       1000000007) %
            1000000007;
      ans = (ans - ((even[v] * V[u]) % 1000000007 * (n - odd[v] - even[v])) %
                       1000000007) %
            1000000007;
      minuss += even[v] * (n - odd[v] - even[v]);
      pluss += odd[v] * (n - odd[v] - even[v]);
    }
  }
  for (long long v : edg[u]) {
    if (v == p) continue;
    dfs2(v, u, upOdd + even[u] - odd[v], upEven + odd[u] - even[v]);
  }
  ans = (ans + (n * V[u]) % 1000000007) % 1000000007;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> V[i];
  }
  for (long long i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    edg[u].push_back(v);
    edg[v].push_back(u);
  }
  dfs1(1, 0);
  dfs2(1, 0, 0, 0);
  ans = (ans + 1000000007) % 1000000007;
  cout << ans << endl;
  return 0;
}
