#include <bits/stdc++.h>
using namespace std;
const int size = 100000;
vector<int> A[size + 1];
long long k[size + 1];
int n, s;
long long x[size + 1], y[size + 1];
void f(int v, int p) {
  if (A[v].size() == 1 && p != -1) {
    x[v] = 0;
    y[v] = k[v] - 1;
  } else {
    vector<long long> X;
    vector<long long> Y;
    for (int i = 0; i < A[v].size(); i++)
      if (A[v][i] != p) {
        f(A[v][i], v);
        X.push_back(x[A[v][i]]);
        Y.push_back(y[A[v][i]]);
      }
    sort(X.begin(), X.end());
    int limit;
    if (p != -1) {
      k[v]--;
      limit = min(k[v], (long long)X.size());
    } else {
      limit = min(k[v], (long long)X.size());
    }
    for (int i = 0; i < limit; i++) {
      x[v] += 2;
      x[v] += X[X.size() - i - 1];
      k[v]--;
    }
    for (int i = 0; i < Y.size(); i++)
      if (k[v] > 0 && Y[i] > 0) {
        long long add = min(k[v], Y[i]);
        k[v] -= add;
        x[v] += (add * 2);
      }
    y[v] = k[v];
  }
}
int main() {
  int a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> k[i];
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    A[a].push_back(b);
    A[b].push_back(a);
  }
  cin >> s;
  f(s, -1);
  cout << x[s] << endl;
  return 0;
}
