#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > matmul(vector<vector<long long> > &a,
                                  vector<vector<long long> > &b) {
  int i, j, k, n = a.size();
  vector<vector<long long> > ans(n, vector<long long>(n));
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      long long temp = 0;
      for (k = 0; k < n; k++)
        temp = (temp + a[i][k] * b[k][j]) % (1000000007LL);
      ans[i][j] = temp;
    }
  return ans;
}
vector<vector<long long> > matpwr(vector<vector<long long> > &a, long long p) {
  int n = a.size();
  vector<vector<long long> > ans(n, vector<long long>(n));
  for (int i = 0; i < n; i++) ans[i][i] = 1;
  while (p) {
    if (p & 1) ans = matmul(ans, a);
    a = matmul(a, a);
    p >>= 1;
  }
  return ans;
}
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long invMod(long long n, long long mod = (1000000007LL)) {
  return pwr(n, mod - 2);
}
int n, root, arr[100004];
long long remaining[100004];
vector<int> adj[100004];
long long dfs(int v, int par) {
  vector<pair<long long, int> > children;
  for (int i = 0; i < (int)adj[v].size(); i++) {
    int vv = adj[v][i];
    if (vv == par || arr[vv] == 0) continue;
    arr[vv]--;
    children.push_back(pair<long long, int>(dfs(vv, v), vv));
  }
  sort(children.begin(), children.end(), greater<pair<long long, int> >());
  long long ans = 0, rem = 0;
  remaining[v] = arr[v];
  for (int i = 0; i < (int)children.size() && remaining[v] > 0; i++) {
    ans += children[i].first + 2;
    remaining[v]--;
    rem += remaining[children[i].second];
  }
  rem = min(rem, remaining[v]);
  ans += 2 * rem;
  remaining[v] -= rem;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  int e = n - 1;
  while (e--) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  scanf("%d", &root);
  printf("%I64d", dfs(root, -1));
  return 0;
}
