#include <bits/stdc++.h>
using namespace std;
const int maxn = 111111;
vector<int> edge[maxn];
long long ans[maxn];
int beavers[maxn];
void dfs(int u, int pre) {
  int remain_beavers_of_children = 0;
  vector<long long> paths;
  for (auto v : edge[u]) {
    if (v ^ pre) {
      beavers[v]--;
      dfs(v, u);
      remain_beavers_of_children += beavers[v];
      paths.push_back(ans[v]);
    }
  }
  sort(paths.begin(), paths.end(), greater<int>());
  for (auto v : paths) {
    if (beavers[u] > 0) {
      beavers[u]--;
      ans[u] += v + 2;
    }
  }
  int go = min(remain_beavers_of_children, beavers[u]);
  ans[u] += go << 1;
  beavers[u] -= go;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> beavers[i];
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  int root;
  cin >> root;
  dfs(root, 0);
  cout << ans[root] << endl;
  return 0;
}
