#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 100010;
vector<vector<int> > edges;
vector<vector<int> > tempe;
bool visited[MAXN];
int beavers[MAXN];
int n, s;
void make_edges(int cur) {
  visited[cur] = true;
  for (int i = 0; i < tempe[cur].size(); i++)
    if (!visited[tempe[cur][i]]) {
      edges[cur].push_back(tempe[cur][i]);
      make_edges(tempe[cur][i]);
    }
}
bool comprev(const pair<long long, long long>& a,
             const pair<long long, long long>& b) {
  if (a.second != b.second) return a.second > b.second;
  return a.first > b.first;
}
pair<long long, long long> solve(int cur, bool keep = false) {
  if (edges[cur].empty()) return make_pair(0, beavers[cur]);
  pair<long long, long long> ret = make_pair(0, beavers[cur]);
  vector<pair<long long, long long> > children(edges[cur].size());
  for (int i = 0; i < edges[cur].size(); i++)
    children[i] = solve(edges[cur][i], true);
  sort(children.begin(), children.end(),
       greater<pair<long long, long long> >());
  int c = 0, tmp;
  while (ret.second > keep && children[c].first && children[c].second &&
         c < children.size()) {
    ret.second--;
    children[c].second--;
    ret.first += children[c++].first + 2;
  }
  c = 0;
  sort(children.begin(), children.end(), comprev);
  while (ret.second > keep && c < children.size()) {
    tmp = min(ret.second - keep, children[c++].second);
    ret.second -= tmp;
    ret.first += tmp * 2;
  }
  return ret;
}
int main() {
  cin >> n;
  edges.resize(n);
  tempe.resize(n);
  int a, b;
  for (int i = 0; i < n; i++) cin >> beavers[i];
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    a--;
    b--;
    tempe[a].push_back(b);
    tempe[b].push_back(a);
  }
  cin >> s;
  s--;
  make_edges(s);
  cout << solve(s).first << endl;
  return 0;
}
