#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("arch=corei7-avx")
using namespace std;
vector<int> cap, extra;
vector<vector<int> > g;
long long dfs(int cur, int prv) {
  if ((cap[cur] == 1 || (int)(g[cur]).size() == 1) && prv != -1) {
    extra[cur] = cap[cur] - 1;
    return 1;
  }
  vector<long long> children;
  for (int nxt : g[cur]) {
    if (nxt == prv) continue;
    children.push_back(dfs(nxt, cur));
  }
  int take = cap[cur];
  if (prv != -1) {
    --take;
  }
  if (take <= (int)(children).size()) {
    sort((children).begin(), (children).end());
    reverse((children).begin(), (children).end());
    long long result = 0;
    for (int(i) = 0; (i) < (take); (i)++) result += 1 + children[i];
    if (prv != -1) {
      ++result;
    }
    return result;
  } else {
    long long result = 0;
    for (int(i) = 0; (i) < ((int)(children).size()); (i)++)
      result += 1 + children[i];
    extra[cur] = take - (int)(children).size();
    for (int nxt : g[cur]) {
      if (nxt == prv) continue;
      if (extra[nxt] < extra[cur]) {
        result += 2 * extra[nxt];
        extra[cur] -= extra[nxt];
      } else {
        result += 2 * extra[cur];
        extra[cur] = 0;
        break;
      }
    }
    if (prv != -1) {
      ++result;
    }
    return result;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  cap.resize(n);
  for (int(i) = 0; (i) < (n); (i)++) cin >> cap[i];
  extra.assign(n, 0);
  g.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 st;
  cin >> st;
  --st;
  cout << dfs(st, -1) << endl;
  return 0;
}
