#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1.5e6 + 5;
const int MAXM = 1.5e6 + 5;
std::vector<int> v[MAXM];
std::vector<int> G[MAXM];
long long n, s;
long long a[MAXM], dp[MAXM];
bool cmp(long long a, long long b) { return a > b; }
void dfs(int u, int fa) {
  int len = G[u].size();
  if (len == 1 && u != s) {
    dp[u] = 1;
    a[u]--;
    return;
  }
  std::vector<long long> v;
  for (int i = 0; i < len; i++) {
    int to = G[u][i];
    if (to != fa) {
      dfs(to, u);
      v.push_back(dp[to]);
    }
  }
  if (u != s) {
    dp[u] = 1;
    a[u]--;
  } else
    dp[u] = 0;
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < v.size(); i++) {
    if (a[u]) {
      dp[u] += v[i] + 1;
      a[u]--;
    } else
      break;
  }
  for (int i = 0; i < len; i++) {
    int to = G[u][i];
    if (to != fa) {
      if (a[u]) {
        dp[u] += min(a[u], a[to]) * 2;
        a[u] -= min(a[u], a[to]);
      } else
        break;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  cin >> s;
  dfs(s, -1);
  cout << dp[s] << endl;
  return 0;
}
