#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
struct arc {
  int f, s, prev;
} arr[300000];
int q[100005];
int beg[100005];
int kol = 0;
void add_arc(int f, int s) {
  f--;
  s--;
  arr[kol].f = f;
  arr[kol].s = s;
  arr[kol].prev = beg[f];
  beg[f] = kol++;
  arr[kol].f = s;
  arr[kol].s = f;
  arr[kol].prev = beg[s];
  beg[s] = kol++;
}
long long tmp[100005];
long long DFS(int pos, int fr = 0, int p = -1) {
  long long child = 0, ret = 0;
  int nfr = 0;
  for (int i = beg[pos]; i != -1; i = arr[i].prev) {
    if (arr[i].s == p) {
      continue;
    }
    if (q[arr[i].s] > 1) {
      q[arr[i].s]--;
      tmp[fr + nfr] = DFS(arr[i].s, fr + nfr, pos) + 1;
      child += q[arr[i].s];
      nfr++;
    } else {
      child += q[arr[i].s];
    }
  }
  sort(tmp + fr, tmp + fr + nfr, greater<long long>());
  if (nfr >= q[pos]) {
    for (int i = 0; i < q[pos]; i++) {
      ret += tmp[fr + i] + 1;
    }
    q[pos] = 0;
  } else {
    for (int i = 0; i < nfr; i++) {
      ret += tmp[fr + i] + 1;
    }
    q[pos] -= nfr;
    ret += 2 * min((long long)q[pos], child);
    q[pos] -= min((long long)q[pos], child);
  }
  return ret;
}
int main() {
  memset(beg, -1, sizeof beg);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &q[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    int f, s;
    scanf("%d%d", &f, &s);
    add_arc(f, s);
  }
  int s;
  scanf("%d", &s);
  s--;
  if (q[s] != 0) {
    cout << DFS(s) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}
