#include <bits/stdc++.h>
using namespace std;
vector<int> G[100005];
long long beaver[100005], dp[100005];
int n, s;
void dfs(int fa, int u) {
  vector<pair<long long, int> > p1;
  dp[u] = 0;
  for (int i = 0; i < G[u].size(); i++) {
    if (fa != G[u][i]) {
      int v = G[u][i];
      beaver[v]--;
      dfs(u, v);
      p1.push_back(make_pair(dp[v], v));
    }
  }
  sort(p1.begin(), p1.end(), greater<pair<long long, int> >());
  long long lim = min((long long)p1.size(), beaver[u]);
  long long leave = 0;
  for (int i = 0; i < lim; i++) {
    dp[u] += p1[i].first + 2;
    beaver[u]--;
    leave += beaver[p1[i].second];
  }
  lim = min(leave, beaver[u]);
  beaver[u] -= lim;
  dp[u] += 2 * lim;
}
void input() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i <= n; i++) {
      G[i].clear();
    }
    for (int i = 1; i <= n; i++) {
      scanf("%I64d", &beaver[i]);
    }
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      G[a].push_back(b);
      G[b].push_back(a);
    }
    scanf("%d", &s);
    dfs(-1, s);
    printf("%I64d\n", dp[s]);
  }
}
int main() {
  input();
  return 0;
}
