#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a <= b)
    return a;
  else
    return b;
}
const int MAXN = 100005;
int t = 0;
int ui, vi;
int n;
struct node {
  int v;
  int next;
} e[2 * MAXN];
int v[MAXN];
long long w[MAXN];
void dfs(int p, int root, long long& left, long long& getans) {
  vector<long long> cget;
  long long leftsum = 0;
  for (int i = v[root]; i != -1; i = e[i].next) {
    if (e[i].v != p && w[e[i].v] > 0) {
      long long ans, cleft = w[e[i].v] - 1;
      dfs(root, e[i].v, cleft, ans);
      cget.push_back(ans);
      leftsum += cleft;
    }
  }
  sort(cget.begin(), cget.end());
  getans = 0;
  for (int i = cget.size() - 1; left && i >= 0; i--) {
    left--;
    getans += cget[i] + 2;
  }
  getans += min(leftsum, left) * 2;
  left -= min(leftsum, left);
}
int main() {
  while (scanf("%d", &n) == 1) {
    t = 0;
    memset(v, -1, sizeof(v));
    for (int i = 1; i <= n; i++) scanf("%lld", &w[i]);
    for (int i = 1; i < n; i++) {
      scanf("%d %d", &ui, &vi);
      e[t].v = vi;
      e[t].next = v[ui];
      v[ui] = t;
      t++;
      e[t].v = ui;
      e[t].next = v[vi];
      v[vi] = t;
      t++;
    }
    int root;
    scanf("%d", &root);
    long long getans, getleft;
    getleft = w[root];
    dfs(0, root, getleft, getans);
    cout << getans << endl;
  }
}
