#include <bits/stdc++.h>
using namespace std;
vector<int> adjList[100010];
long long int beavers[100010];
long long int dfs(int u, int p) {
  vector<long long int> vals;
  long long int total = 0;
  long long int rem = 0;
  for (auto v : adjList[u]) {
    if (v == p || beavers[v] == 0) continue;
    beavers[v] -= 1;
    long long int ret = dfs(v, u);
    rem += beavers[v];
    vals.push_back(ret + 2);
  }
  sort(vals.rbegin(), vals.rend());
  if (beavers[u] >= vals.size()) {
    for (auto x : vals) total += x;
    beavers[u] -= vals.size();
    long long int del = min(rem, beavers[u]);
    beavers[u] -= del;
    total += 2 * del;
  } else {
    for (int i = 0; i < beavers[u]; i++) total += vals[i];
    beavers[u] = 0;
  }
  return total;
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%lld", &beavers[i]);
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  int S;
  scanf("%d", &S);
  cout << dfs(S, -1) << endl;
  return 0;
}
