#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
string filename = "test";
int k[100010];
vector<int> adj[100010];
int n;
bool cmp(const pair<pair<long long, long long>, int>& a,
         const pair<pair<long long, long long>, int>& b) {
  if (a.first.first != b.first.first) return a.first.first > b.first.first;
  return a.second < b.second;
}
pair<long long, long long> go(int v, int p) {
  if (adj[v].size() == 1 && adj[v][0] == p) {
    return pair<long long, long long>(0, k[v] - 1);
  }
  vector<pair<pair<long long, long long>, int> > child_res;
  for (int _n(adj[v].size()), i(0); i < _n; i++)
    if (adj[v][i] != p && k[adj[v][i]] > 0) {
      child_res.push_back(
          pair<pair<long long, long long>, int>(go(adj[v][i], v), i));
    }
  sort((child_res).begin(), (child_res).end(), cmp);
  int left = k[v] - 1;
  long long sum = 0;
  if (left >= child_res.size()) {
    for (int _n(child_res.size()), i(0); i < _n; i++)
      sum += (child_res[i].first.first + 2);
    left -= child_res.size();
  } else {
    for (int _n(left), i(0); i < _n; i++) sum += (child_res[i].first.first + 2);
    left = 0;
  }
  if (left > 0) {
    for (int _n(child_res.size()), i(0); i < _n; i++) {
      if (left == 0) break;
      long long add = (((left) < (child_res[i].first.second))
                           ? (left)
                           : (child_res[i].first.second));
      left -= add;
      sum += 2 * add;
    }
  }
  return pair<long long, long long>(sum, left);
}
int main() {
  scanf("%d", &n);
  for (int _n(n), i(0); i < _n; i++) {
    scanf("%d", &k[i]);
  }
  int x, y;
  for (int _n(n - 1), i(0); i < _n; i++) {
    scanf("%d %d", &x, &y);
    --x;
    --y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int s;
  scanf("%d", &s);
  --s;
  k[s]++;
  pair<long long, long long> res = go(s, -1);
  cout << res.first << endl;
  return 0;
}
