#include <bits/stdc++.h>
using namespace std;
inline void read(register int *n) {
  register char c;
  *n = 0;
  do {
    c = getchar();
  } while (c < '0' || c > '9');
  do {
    *n = c - '0' + *n * 10;
    c = getchar();
  } while (c >= '0' && c <= '9');
}
long long n, k[101 * 1000];
vector<int> adj[101 * 1000];
long long cnt(int pos, int par = -1) {
  vector<long long> V;
  for (__typeof((adj[pos]).begin()) next = (adj[pos]).begin();
       next != (adj[pos]).end(); ++next)
    if (*next != par) {
      k[*next]--;
      V.push_back(cnt(*next, pos) + 2);
    }
  long long tot = 0;
  sort((V).begin(), (V).end(), greater<long long>());
  int lim = min(k[pos], (long long)((int)(V).size()));
  for (register int i = (0); i < (int)(lim); ++i) tot += V[i], k[pos]--;
  for (__typeof((adj[pos]).begin()) next = (adj[pos]).begin();
       next != (adj[pos]).end(); ++next)
    if (*next != par) {
      long long g = min(k[pos], k[*next]);
      k[pos] -= g;
      k[*next] -= g;
      tot += g * 2;
    }
  return tot;
}
int main(int argv, char **argc) {
  ios::sync_with_stdio(false);
  cin >> n;
  for (register int i = (0); i < (int)(n); ++i) cin >> k[i];
  for (register int i = (1); i < (int)(n); ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int s;
  cin >> s;
  cout << cnt(s - 1) << endl;
  return 0;
}
