#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
double eps = 1e-7;
struct node {
  int u, v, next;
} e[N * 10];
int t, first[N];
long long num[N];
long long sum[N];
void add(int u, int v) {
  t++;
  e[t].u = u;
  e[t].v = v;
  e[t].next = first[u];
  first[u] = t;
}
int n, s;
long long cnt = 0;
long long dfs(int u, int pre) {
  bool leaf = true;
  vector<long long> p;
  long long ans = 0;
  for (int i = first[u]; i != -1; i = e[i].next) {
    int v = e[i].v;
    if (v == pre) continue;
    leaf = false;
    if (!num[v]) continue;
    num[v]--;
    p.push_back(dfs(v, u));
  }
  if (!leaf) {
    sort(p.begin(), p.end());
    for (int i = p.size() - 1; i >= 0; i--) {
      if (!num[u]) break;
      num[u]--;
      ans += p[i] + 2;
    }
    for (int i = first[u]; i != -1; i = e[i].next) {
      int v = e[i].v;
      if (v == pre) continue;
      int t = min(num[u], num[v]);
      num[u] -= t;
      num[v] -= t;
      ans += 2 * t;
    }
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num[i];
  }
  int u, v;
  memset(first, -1, sizeof(first));
  memset(sum, 0, sizeof(sum));
  cnt = 0;
  t = -1;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  cin >> u;
  cout << dfs(u, 0) << endl;
  return 0;
}
