#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int n;
int b[MAXN];
vector<int> adj[MAXN];
bool v[MAXN];
long long best(int node) {
  long long ret = 0, left = 0;
  v[node] = true;
  vector<pair<long long, int> > vals;
  for (int i = 0; i < adj[node].size(); i++) {
    if (!v[adj[node][i]] && b[adj[node][i]] >= 2) {
      b[adj[node][i]]--;
      vals.push_back(make_pair(best(adj[node][i]), adj[node][i]));
      b[adj[node][i]]++;
    }
  }
  sort(vals.begin(), vals.end(), greater<pair<long long, int> >());
  int cur = 0;
  while (cur < vals.size() && b[node]) {
    b[node]--;
    b[vals[cur].second]--;
    ret += vals[cur++].first + 2;
  }
  for (int i = 0; i < adj[node].size(); i++)
    if (!v[adj[node][i]]) left += b[adj[node][i]];
  left = min(left, (long long)b[node]);
  b[node] -= left;
  v[node] = false;
  return ret + left * 2;
}
int main() {
  int s, t;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 1; i < n; i++) {
    cin >> s >> t;
    adj[s - 1].push_back(t - 1);
    adj[t - 1].push_back(s - 1);
  }
  cin >> s;
  cout << best(s - 1) << endl;
  return 0;
}
