#include <bits/stdc++.h>
using namespace std;
long long solve(int v, int p, vector<int>& count, vector<vector<int> >& adj,
                bool isRoot) {
  vector<pair<long long, int> > childs;
  for (int i = (0); i < (((int)adj[v].size())); ++i) {
    int v2 = adj[v][i];
    if (v2 == p) continue;
    if (count[v2])
      childs.push_back(make_pair(solve(v2, v, count, adj, false), v2));
  }
  sort(childs.begin(), childs.end());
  reverse(childs.begin(), childs.end());
  long long result = !isRoot;
  count[v] -= !isRoot;
  for (int i = (0); i < (((int)childs.size())); ++i) {
    if (count[v] == 0) break;
    result += childs[i].first + 1;
    --count[v];
  }
  for (int i = (0); i < (((int)childs.size())); ++i) {
    int c = min(count[v], count[childs[i].second]);
    result += 2 * c;
    count[v] -= c;
  }
  return result;
}
int main() {
  int n;
  cin >> n;
  vector<int> count(n);
  for (int i = (0); i < ((n)); ++i) cin >> count[i];
  vector<vector<int> > adj(n);
  for (int i = (0); i < ((n - 1)); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int s;
  cin >> s;
  --s;
  cout << solve(s, -1, count, adj, true) << endl;
  return 0;
}
