#include <bits/stdc++.h>
using namespace std;
int N, a[111111];
vector<int> n[111111];
stack<int> s, f;
long long g[111111];
long long get(int start) {
  int Start = start, father;
  int i, S;
  bool ok;
  vector<long long> pos;
  s.push(start);
  f.push(-1);
  while (!s.empty()) {
    start = s.top();
    father = f.top();
    S = n[start].size();
    long long disp = 0, sum = 0;
    ok = true;
    for (i = 0; i < S; i++) {
      if (n[start][i] == father) continue;
      if (g[n[start][i]] == -1) {
        a[n[start][i]]--;
        s.push(n[start][i]);
        f.push(start);
        ok = false;
      }
    }
    if (!ok) continue;
    pos.clear();
    for (i = 0; i < S; i++) {
      if (n[start][i] == father) continue;
      pos.push_back(g[n[start][i]]);
      disp += a[n[start][i]];
    }
    sort(pos.begin(), pos.end());
    for (i = pos.size() - 1; i >= 0; i--) {
      if (a[start] == 0) break;
      sum += pos[i] + 2;
      a[start]--;
    }
    sum += 2 * min((long long)a[start], disp);
    a[start] -= (min((long long)a[start], disp));
    s.pop();
    f.pop();
    g[start] = sum;
  }
  return g[Start];
}
int main(int argc, char *argv[]) {
  int i, A, B;
  scanf("%d", &N);
  for (i = 0; i < N; i++) scanf("%d", a + i);
  for (i = 0; i < N - 1; i++) {
    scanf("%d%d", &A, &B);
    A--;
    B--;
    n[A].push_back(B);
    n[B].push_back(A);
  }
  for (i = 0; i < N + 1; i++) g[i] = -1;
  scanf("%d", &A);
  printf("%I64d\n", get(A - 1));
  return 0;
}
