#include <bits/stdc++.h>
using namespace std;
vector<long long> al[100100];
long long a[100100], t[100100];
pair<long long, long long> dfs(long long v, long long p = -1) {
  pair<long long, long long> ans = make_pair(0, a[v]);
  vector<long long> vec;
  long long k = 0;
  for (int i = 0; i < al[v].size(); i++)
    if (al[v][i] - p) {
      pair<long long, long long> x = dfs(al[v][i], v);
      vec.push_back(x.first + 1);
      k += x.second;
    }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0; i < min(a[v], (long long)vec.size()); i++)
    ans.first += vec[i] + 1;
  ans.second -= min(a[v], (long long)vec.size());
  ans.first += 2 * min(ans.second, k);
  ans.second = max(ans.second - k, 0LL);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i], a[i]--;
  for (long long i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    x--;
    y--;
    al[y].push_back(x), al[x].push_back(y);
  }
  long long s;
  cin >> s;
  s--;
  a[s]++;
  cout << dfs(s).first << endl;
  return 0;
}
