#include <bits/stdc++.h>
#pragma  comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 100005;
vector<int> edge[maxn];
int val[maxn];
long long dp[maxn];
void dfs(int u, int fa) {
  val[u]--;
  dp[u] = 1;
  if (edge[u].size() == 0) {
    return;
  }
  priority_queue<long long> que;
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (v == fa || val[v] == 0) continue;
    dfs(v, u);
    que.push(dp[v]);
  }
  while (val[u] && !que.empty()) {
    dp[u] += que.top() + 1;
    val[u]--;
    que.pop();
  }
  if (val[u]) {
    for (int i = 0; i < edge[u].size(); i++) {
      int v = edge[u][i];
      if (v == fa || val[v] == 0) continue;
      if (val[u] > val[v]) {
        val[u] -= val[v];
        dp[u] += 2 * val[v];
      } else {
        dp[u] += 2 * val[u];
        val[u] = 0;
      }
      if (!val[u]) break;
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  int root;
  scanf("%d", &root);
  val[root]++;
  dfs(root, 0);
  cout << dp[root] - 1 << endl;
  return 0;
}
