#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<long long> adj[N];
long long bvr[N], dp[N], n, root;
bool mark[N];
void DFS(long long v) {
  mark[v] = true;
  bvr[v] -= 1;
  dp[v] += 1;
  long long childgot = 0, sumdp = 0;
  vector<int> tmp;
  for (long long i = 0; i < adj[v].size(); i++) {
    if (!mark[adj[v][i]] && bvr[adj[v][i]] > 1) {
      DFS(adj[v][i]);
      childgot += bvr[adj[v][i]];
      sumdp += dp[adj[v][i]];
      tmp.push_back(dp[adj[v][i]]);
    } else if (!mark[adj[v][i]] && bvr[adj[v][i]] == 1) {
      mark[adj[v][i]] = true;
      dp[adj[v][i]] = 1;
      bvr[adj[v][i]] = 0;
      sumdp += 1;
      tmp.push_back(1);
    }
  }
  sort(tmp.begin(), tmp.begin() + tmp.size());
  if (bvr[v] < tmp.size()) {
    for (long long i = tmp.size() - 1; i >= tmp.size() - bvr[v]; i--)
      dp[v] += tmp[i];
    dp[v] += bvr[v];
    bvr[v] = 0;
    return;
  }
  dp[v] += sumdp;
  dp[v] += tmp.size();
  bvr[v] -= tmp.size();
  if (childgot >= bvr[v]) {
    dp[v] += ((long long)2 * bvr[v]);
    bvr[v] = 0;
    return;
  }
  dp[v] += ((long long)2 * childgot);
  bvr[v] -= childgot;
  return;
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> bvr[i];
  for (long long i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cin >> root;
  bvr[root]++;
  if (bvr[root] > 1) DFS(root);
  cout << (long long)dp[root] - (long long)1;
  return 0;
}
