#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 5e5 + 10;
long long arr[N], dp[N], rem[N];
int n;
vector<int> v[N];
void dfs(int s, int p = 0) {
  vector<long long> temp;
  long long sum = 0;
  dp[s]++;
  arr[s]--;
  for (auto it : v[s]) {
    if (it == p) continue;
    dfs(it, s);
    temp.push_back(dp[it]);
    sum += rem[it];
  }
  sort(temp.rbegin(), temp.rend());
  for (auto it : temp) {
    if (it == 0) break;
    if (arr[s]) {
      dp[s] += it + 1;
      arr[s]--;
    }
  }
  long long mn = min(sum, arr[s]);
  dp[s] += mn * 2ll;
  arr[s] -= mn;
  rem[s] = arr[s];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int s;
  cin >> s;
  ++arr[s];
  dfs(s);
  cout << dp[s] - 1 << "\n";
  return 0;
}
