#include <bits/stdc++.h>
using namespace std;
void require(bool cond, const string& message = "Runtime error") {
  if (!cond) {
    cerr << message << endl;
    assert(false);
  }
}
void readData() {}
vector<long long> cnt;
int n;
vector<vector<int> > g;
pair<long long, long long> dfs(int v, int p) {
  vector<pair<long long, long long> > t;
  for (int i = 0; i < int(g[v].size()); ++i) {
    int u = g[v][i];
    if (u == p) continue;
    if (cnt[u] == 0) continue;
    --cnt[u];
    t.push_back(dfs(u, v));
  }
  sort(t.begin(), t.end());
  pair<long long, long long> res;
  res.first = 0, res.second = cnt[v];
  long long sum = 0;
  for (int i = t.size(); i > 0; --i) {
    if (res.second == 0) break;
    --res.second;
    res.first += t[i - 1].first + 2;
    sum += t[i - 1].second;
  }
  if (res.second == 0) return res;
  res.first += min(res.second, sum) * 2;
  res.second = max(0ll, res.second - sum);
  return res;
}
void solve() {
  cin >> n;
  cnt.resize(n);
  g.resize(n);
  for (int i = 0; i < int(n); ++i) cin >> cnt[i];
  for (int i = 0; i < int(n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int s;
  cin >> s;
  --s;
  cout << dfs(s, -1).first << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  readData();
  solve();
  return 0;
}
