#include <bits/stdc++.h>
using namespace std;
vector<long long> k;
vector<long long> s;
vector<vector<long long>> g;
struct bigger {
  bool operator()(const pair<long long, long long> &a,
                  const pair<long long, long long> &b) {
    return tie(a.first, a.second) > tie(b.first, b.second);
  }
};
void dfs(long long v, long long p) {
  if (g[v].size() == 1 && p != -1) return;
  multiset<pair<long long, long long>, bigger> ms;
  for (long long u : g[v]) {
    if (p == u || k[u] == 0) continue;
    k[u]--;
    dfs(u, v);
    ms.insert({s[u], k[u]});
  }
  while (!ms.empty()) {
    if (k[v] == 0) break;
    auto [a, r] = *ms.begin();
    ms.erase(ms.begin());
    if (a != 0) {
      k[v]--;
      s[v] += 2;
      s[v] += a;
      if (r >= 1) ms.insert({0LL, r - 1});
    } else {
      k[v]--;
      long long l = min(k[v] + 1, r + 1);
      s[v] += 2 * l;
      k[v] -= l - 1;
    }
  }
}
signed main() {
  long long n;
  cin >> n;
  k.resize(n);
  g.resize(n);
  s.resize(n);
  for (long long i = 0; i < n; ++i) {
    cin >> k[i];
  }
  for (long long i = 0; i < n - 1; ++i) {
    long long u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  long long strt;
  cin >> strt;
  --strt;
  dfs(strt, -1);
  cout << s[strt];
  return 0;
}
