#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int n, a, z;
vector<vector<int> > G;
long long dp[maxn], b[maxn], ost[maxn];
vector<vector<long long> > fdp;
void dfs(int a, int p) {
  for (int i = 0; i < G[a].size(); i++) {
    int to = G[a][i];
    if (to != p && b[to] >= 2) {
      dfs(to, a);
      fdp[a].push_back(dp[to]);
    }
  }
  sort(fdp[a].begin(), fdp[a].end());
  long long q = 0;
  ost[a] = b[a] - 1;
  for (int i = fdp[a].size() - 1; i >= 0 && ost[a] && fdp[a][i]; i--) {
    q += fdp[a][i] + 2;
    ost[a]--;
  }
  for (int i = 0; i < G[a].size() && ost[a]; i++) {
    int to = G[a][i];
    if (to != p && ost[to] >= 1) {
      long long sz = min(ost[a], ost[to]);
      ost[a] -= sz;
      q += 2 * sz;
    }
  }
  dp[a] = q;
  if (q == 0) ost[a] = b[a];
}
int main() {
  cin >> n;
  G.resize(n);
  fdp.resize(n);
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) dp[i] = 0;
  for (int i = 0; i < n; i++) ost[i] = b[i];
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> z;
    a--;
    z--;
    G[a].push_back(z);
    G[z].push_back(a);
  }
  cin >> z;
  z--;
  b[z]++;
  dfs(z, z);
  cout << dp[z];
}
