#include <bits/stdc++.h>
using namespace std;
int n, s;
vector<int> adj[100010];
bool vis[100010];
long long qtde[100010], best[100010], rem[100010];
void go(int u) {
  vis[u] = true;
  if (adj[u].size() == 1 && u != s) {
    best[u] = 0LL;
    rem[u] = qtde[u];
    return;
  }
  multiset<long long, greater<long long> > myset;
  multiset<long long, greater<long long> >::iterator it;
  long long R = 0LL;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (vis[v]) continue;
    go(v);
    if (best[v] > 0LL) myset.insert(best[v]);
    R += rem[v];
  }
  best[u] = 0LL;
  if (u != s) {
    qtde[u]--;
    best[u] = 1LL;
  }
  for (it = myset.begin(); it != myset.end() && qtde[u] > 0LL; it++) {
    best[u] += (*it) + 1LL;
    qtde[u]--;
  }
  long long mn = min(R, qtde[u]);
  best[u] += 2LL * mn;
  rem[u] = qtde[u] - mn;
  return;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> qtde[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  memset(vis, false, sizeof(vis));
  cin >> s;
  s--;
  go(s);
  cout << best[s] << endl;
  return 0;
}
