#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> T;
vector<long> K, D;
long n, s;
long long dfs(int q, int from) {
  if (!K[q]) return 0;
  K[q]--;
  long long sum = 1;
  vector<long long> ff(D[q]);
  for (int i = 0; i < D[q]; ++i) {
    if (T[q][i] != from)
      ff[i] = dfs(T[q][i], q) + 1;
    else
      ff[i] = 0;
  }
  sort(ff.begin(), ff.end());
  reverse(ff.begin(), ff.end());
  long long h = min(K[q], D[q]);
  for (int i = 0; i < h; ++i) {
    sum += (ff[i]);
    if (ff[i]) K[q]--;
  }
  for (int i = 0; i < D[q] && K[q] > 0; ++i)
    if (K[T[q][i]] > 0 && T[q][i] != from) {
      h = min(K[T[q][i]], K[q]);
      K[q] -= h;
      sum += 2 * h;
    }
  return sum;
}
int main() {
  cin >> n;
  K.resize(n);
  D.resize(n, 0);
  for (int i = 0; i < n; ++i) cin >> K[i];
  T.resize(n);
  long x, y;
  for (int i = 0; i < n - 1; ++i) {
    cin >> x >> y;
    x--, y--;
    T[x].push_back(y);
    T[y].push_back(x);
    D[x]++;
    D[y]++;
  }
  cin >> s;
  s--;
  K[s]++;
  cout << (dfs(s, -1) - 1);
}
