#include <bits/stdc++.h>
std::vector<int> vec[100010];
int n, st;
int bea[100010];
long long int dy[100010];
bool check[100010];
void memo(int now) {
  int s, child, i;
  int rest = 0;
  std::vector<long long int> k;
  check[now] = true;
  s = vec[now].size();
  if (s == 1 && now != st) {
    return;
  }
  for (i = 0; i < s; i++) {
    child = vec[now][i];
    if (check[child]) continue;
    memo(child);
    k.push_back(dy[child]);
    rest += bea[child] - 1;
  }
  std::sort(k.begin(), k.end());
  s = k.size();
  for (i = s - 1; i >= 0; i--) {
    if (bea[now] > 1) {
      dy[now] += k[i] + 2;
      bea[now]--;
    } else
      break;
  }
  if (bea[now] > 1) {
    if (rest >= (bea[now] - 1)) {
      dy[now] += 2 * (bea[now] - 1);
      bea[now] = 1;
    } else {
      dy[now] += 2 * rest;
      bea[now] -= rest;
    }
  }
}
int main(void) {
  int a, b, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &bea[i]);
  }
  for (i = 1; i < n; i++) {
    scanf("%d %d", &a, &b);
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  scanf("%d", &st);
  bea[st]++;
  memo(st);
  printf("%I64d\n", dy[st]);
  return false;
}
