#include <bits/stdc++.h>
using namespace std;
int w[100001];
vector<int> g[100001];
long long q[100001];
long long dfs(int f, int s) {
  long long res = 1, rest = 0, d;
  if (q[s] != -1) return q[s];
  w[s]--;
  q[s] = 0;
  vector<pair<long long, int> > b;
  for (int i = 0; i < g[s].size(); i++)
    if (g[s][i] != f) {
      b.push_back(make_pair(dfs(s, g[s][i]), g[s][i]));
      rest += w[g[s][i]];
    }
  sort(b.rbegin(), b.rend());
  int k = 0;
  while (w[s]) {
    if (k < b.size() && b[k].first)
      res += b[k].first + 1, q[b[k++].second] = 0, w[s]--;
    else {
      d = min(rest, (long long)w[s]);
      res += 2 * d, w[s] -= d;
      break;
    }
  }
  return q[s] = res;
}
int main() {
  int i, j, k, n, s, res = 0;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> w[i];
  for (i = 1; i < n; i++) {
    cin >> j >> k;
    g[j].push_back(k);
    g[k].push_back(j);
  }
  cin >> s;
  memset(q, 255, sizeof(q));
  w[s]++;
  cout << dfs(0, s) - 1 << endl;
  cin >> i;
  return 0;
}
