func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using graph = vector<vector<int>>;   const ll mod = 1e9 + 7;   const int MAX = 2e5;   int n;   map<pii, ll> memo;   int size[MAX];   void dfs1(int v, int prev, const graph& G, const vector<ll>& V) {     pii p(prev, v);     ll res = 0;     int cnt = 1;     for (auto to : G[v])       if (to != prev) {         dfs1(to, v, G, V);         pii q(v, to);         cnt += size[to];         res = (res - memo[q] + mod) % mod;       }     res = (res + cnt * V[v] % mod) % mod;     size[v] = cnt;     memo[p] = res;   }   void dfs2(int v, int prev, const graph& G, const vector<ll>& V) {     ll val = memo[pii(-1, v)];     for (auto to : G[v])       if (to != prev) {         ll x = memo[pii(v, to)];         ll c = size[to];         ll tmp = memo[pii(to, v)] = (val + x - V[v] * c % mod + mod) % mod;         memo[pii(-1, to)] = (x - tmp + mod + V[to] * (n - c) % mod) % mod;         dfs2(to, v, G, V);       }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     vector<ll> V(n);     for (int i = 0; i < n; i++) {       cin >> V[i];       V[i] = (V[i] + mod) % mod;     }     graph G(n);     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--, b--;       G[a].push_back(b);       G[b].push_back(a);     }     dfs1(0, -1, G, V);     dfs2(0, -1, G, V);     ll res = 0;     for (int i = 0; i < n; i++) {       res = (res + memo[pii(-1, i)]) % mod;     }     cout << res << endl;     return 0;   }   