#include <bits/stdc++.h>
using namespace std;
static long long n;
static vector<long long> beavers;
static vector<vector<long> > edges;
static long s;
static vector<long long> initial;
static vector<long long> remaining;
static vector<long> parents;
static stack<pair<long, bool> > work;
int main(void) {
  ios::sync_with_stdio(false);
  cin >> n;
  beavers.reserve(n);
  edges.resize(n);
  initial.resize(n);
  remaining.resize(n);
  parents.resize(n);
  for (long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    beavers.push_back(k);
  }
  for (long i = 0; i < n - 1; i++) {
    long j, k;
    cin >> j >> k;
    j--;
    k--;
    edges[j].push_back(k);
    edges[k].push_back(j);
  }
  cin >> s;
  s--;
  parents[s] = -1;
  edges[s].push_back(-1);
  beavers[s]++;
  work.push(make_pair(s, true));
  while (!work.empty()) {
    long node = work.top().first;
    bool first_visit = work.top().second;
    work.pop();
    if (first_visit) {
      work.push(make_pair(node, false));
      edges[node].erase(
          std::remove(edges[node].begin(), edges[node].end(), parents[node]),
          edges[node].end());
      for (auto edge : edges[node]) {
        parents[edge] = node;
        work.push(make_pair(edge, true));
      }
    } else {
      if (beavers[node] > 0) {
        sort(edges[node].begin(), edges[node].end(),
             [](long node1, long node2) {
               return initial[node1] > initial[node2];
             });
        initial[node] = 1;
        remaining[node] = beavers[node] - 1;
        for (auto edge : edges[node]) {
          if (remaining[node] > 0) {
            initial[node] += (initial[edge] + 1);
            remaining[node]--;
          }
        }
        for (auto edge : edges[node]) {
          long long max_visits = min(remaining[node], remaining[edge]);
          initial[node] += (2 * max_visits);
          remaining[node] -= max_visits;
        }
      }
    }
  }
  cout << (initial[s] - 1) << endl;
  return 0;
}
