#include <bits/stdc++.h>
using namespace std;
bool us[(100005)];
int n, Q[(100005)], fa[(100005)], Rt, c[(100005)];
long long f[(100005)], li[(100005)];
vector<int> a[(100005)];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &c[i]);
    a[i].clear();
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[u].push_back(v);
    a[v].push_back(u);
  }
  scanf("%d", &Rt);
  memset(us, 0, sizeof(us));
  Q[1] = Rt;
  us[Rt] = 1;
  for (int top = 0, tail = 1; top < tail;) {
    int u = Q[++top];
    for (int o = 0; o < a[u].size(); ++o) {
      int v = a[u][o];
      if (us[v]) continue;
      us[v] = 1;
      fa[v] = u;
      Q[++tail] = v;
    }
  }
  for (int i = n; i >= 1; --i) {
    int u = Q[i];
    li[0] = 0;
    long long ac = 0;
    for (int o = 0; o < a[u].size(); ++o) {
      int v = a[u][o];
      if (fa[v] != u) continue;
      li[++li[0]] = f[v];
      ac += c[v];
    }
    sort(li + 1, li + li[0] + 1);
    int lim = c[u] - 1;
    if (u == Rt) ++lim;
    f[u] = c[u] - lim;
    for (int o = li[0]; o >= 1 && lim > 0; --o, --lim) f[u] += li[o] + 1;
    f[u] += (int)min((long long)lim, ac) * 2;
    c[u] = lim - (int)min((long long)lim, ac);
  }
  printf("%I64d\n", f[Rt]);
  return 0;
}
