#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct node {
  long long t, next;
} e[maxn * 2];
long long n, st, kk, box[maxn];
long long a[maxn], f[maxn];
void add(int s, int t) {
  e[kk].t = t, e[kk].next = box[s];
  box[s] = kk++;
}
void dfs(int r, int fa) {
  a[r]--;
  f[r] = 1;
  long long sum = 0;
  priority_queue<long long> q;
  for (int i = box[r]; ~i; i = e[i].next)
    if (fa != e[i].t) {
      int s = e[i].t;
      if (a[s] == 0) continue;
      dfs(s, r);
      sum += a[s];
      q.push(f[s]);
    }
  while (a[r] && !q.empty()) a[r]--, f[r] += q.top() + 1, q.pop();
  f[r] += min(a[r], sum) * 2;
  a[r] -= min(a[r], sum);
}
void init() {
  kk = 0;
  memset(box, -1, sizeof(box));
  cin >> n;
  long long i;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i < n; i++) {
    long long s, t;
    scanf("%d%d", &s, &t);
    add(s, t);
    add(t, s);
  }
  cin >> st;
  a[st]++;
  if (a[st] == 1)
    cout << 0 << endl;
  else {
    dfs(st, st);
    cout << f[st] - 1 << endl;
  }
}
int main() {
  init();
  return 0;
}
