#include <bits/stdc++.h>
using namespace std;
vector<int> k;
vector<vector<int> > g;
vector<pair<long long, int> > f;
void dfs(int v, int p = -1) {
  f[v] = pair<long long, int>(0, k[v]);
  if (v != p) f[v].second--;
  if (g[v].empty() || (g[v].size() == 1 && g[v][0] == p)) return;
  vector<pair<long long, int> > d;
  for (size_t i = 0; i < g[v].size(); i++) {
    if (g[v][i] == p) continue;
    dfs(g[v][i], v);
    d.push_back(pair<long long, int>(f[g[v][i]]));
  }
  sort(d.begin(), d.end(), greater<pair<long long, int> >());
  for (size_t i = 0; i < d.size() && f[v].second > 0; i++) {
    f[v].first += d[i].first + 2;
    f[v].second--;
  }
  for (size_t i = 0; i < d.size() && f[v].second > 0; i++) {
    int w = min(f[v].second, d[i].second);
    f[v].first += w * 2;
    f[v].second -= w;
  }
}
int main() {
  int n;
  cin >> n;
  k.resize(n);
  for (int i = 0; i < n; i++) cin >> k[i];
  g.resize(n);
  f.resize(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);
  }
  int s;
  cin >> s;
  s--;
  dfs(s, s);
  cout << f[s].first << endl;
  return 0;
}
