#include <bits/stdc++.h>
using namespace std;
vector<int> ve[100005];
int a[100005];
int n;
void dfs(int now, int pre, long long &Max, int &remain) {
  vector<long long> ve_Max;
  vector<int> ve_remain;
  for (int i = 0; i < ve[now].size(); i++) {
    if (ve[now][i] != pre && a[ve[now][i]] > 0) {
      long long tmp_Max;
      int tmp_remain = a[ve[now][i]] - 1;
      dfs(ve[now][i], now, tmp_Max, tmp_remain);
      ve_Max.push_back(tmp_Max);
      ve_remain.push_back(tmp_remain);
    }
  }
  sort(ve_Max.begin(), ve_Max.end());
  Max = 0;
  for (int i = ve_Max.size() - 1; i >= 0 && remain; i--) {
    Max += ve_Max[i] + 2;
    remain--;
  }
  for (int i = 0; i < ve_remain.size() && remain; i++) {
    Max += min(remain, ve_remain[i]) * 2;
    remain -= min(remain, ve_remain[i]);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    ve[u].push_back(v);
    ve[v].push_back(u);
  }
  int fa;
  cin >> fa;
  long long ans = 0;
  dfs(fa, 0, ans, a[fa]);
  cout << ans << endl;
}
