#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000000 + 7;
struct Node {
  long long vp, vn;
  vector<int> to;
  int down0;
  int down1;
  int up0;
  int up1;
};
vector<Node> g;
long long norm(long long a) {
  while (a < 0) a += MOD;
  a %= MOD;
  return a;
}
void Dfs1(int i, int from) {
  g[i].down0 = 0;
  g[i].down1 = 1;
  for (int j = 0; j < int(g[i].to.size()); ++j) {
    int to = g[i].to[j];
    if (to == from) continue;
    Dfs1(to, i);
    g[i].down0 += g[to].down1;
    g[i].down1 += g[to].down0;
  }
}
void Dfs2(int i, int from, int back0, int back1) {
  g[i].up0 = back0;
  g[i].up1 = back1;
  int up0 = back1;
  int up1 = back0 + 1;
  for (int j = 0; j < int(g[i].to.size()); ++j) {
    int to = g[i].to[j];
    if (to == from) continue;
    up0 += g[to].down1;
    up1 += g[to].down0;
  }
  for (int j = 0; j < int(g[i].to.size()); ++j) {
    int to = g[i].to[j];
    if (to == from) continue;
    Dfs2(to, i, up0 - g[to].down1, up1 - g[to].down0);
  }
}
long long Dfs3(int i, int from) {
  int c0 = 0;
  int c1 = 0;
  for (int j = 0; j < int(g[i].to.size()); ++j) {
    int to = g[i].to[j];
    if (to == from) {
      c0 += g[i].up0;
      c1 += g[i].up1;
    } else {
      c0 += g[to].down0;
      c1 += g[to].down1;
    }
  }
  long long total = (c0 + c1 + 1) * g[i].vp % MOD;
  for (int j = 0; j < int(g[i].to.size()); ++j) {
    int to = g[i].to[j];
    int cq0, cq1;
    if (to == from) {
      cq0 = g[i].up0;
      cq1 = g[i].up1;
    } else {
      cq0 = g[to].down0;
      cq1 = g[to].down1;
    }
    int cc0 = c0 - cq0;
    int cc1 = c1 - cq1;
    int cc = cc0 + cc1 + 1;
    total += ((long long)cq0 * cc) % MOD * g[i].vp;
    total += ((long long)cq1 * cc) % MOD * g[i].vn;
    total %= MOD;
  }
  for (int j = 0; j < int(g[i].to.size()); ++j) {
    int to = g[i].to[j];
    if (to == from) continue;
    total += Dfs3(to, i);
  }
  return total % MOD;
}
int main() {
  int n;
  cin >> n;
  g.resize(n);
  for (int i = 0; i < int(n); ++i) {
    long long a;
    cin >> a;
    g[i].vp = norm(a);
    g[i].vn = norm(-a);
  }
  for (int i = 0; i < int(n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].to.push_back(b);
    g[b].to.push_back(a);
  }
  Dfs1(0, -1);
  Dfs2(0, -1, 0, 0);
  long long res = Dfs3(0, -1);
  cout << res << endl;
  return 0;
}
