#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int n, s;
int k[N];
vector<int> g[N];
long long f[N], h[N];
struct Pair {
  long long f, h;
  Pair(long long f, long long h) {
    this->f = f;
    this->h = h;
  }
  bool operator<(const Pair &x) const { return f > x.f; }
};
void dfs(int v, int p) {
  vector<Pair> ch;
  for (int i = 0; i < g[v].size(); i++)
    if (g[v][i] != p) {
      dfs(g[v][i], v);
      ch.push_back(Pair(f[g[v][i]], h[g[v][i]]));
    }
  if (k[v] < ch.size()) {
    sort(ch.begin(), ch.end());
    h[v] = 0;
    f[v] = 2 * k[v];
    for (int i = 0; i < k[v]; i++) f[v] += ch[i].f;
    return;
  }
  f[v] = 2 * ch.size();
  long long sum = 0;
  for (int i = 0; i < ch.size(); i++) {
    f[v] += ch[i].f;
    sum += ch[i].h;
  }
  k[v] -= ch.size();
  if (sum >= k[v]) {
    h[v] = 0;
    f[v] += 2 * k[v];
    return;
  }
  h[v] = k[v] - sum;
  f[v] += 2 * sum;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", k + i);
    k[i]--;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  scanf("%d", &s);
  s--;
  k[s]++;
  dfs(s, -1);
  printf("%lld", f[s]);
  return 0;
}
