#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
long long ans[maxn], k[maxn];
int n;
vector<int> g[maxn];
void Dfs(int v, int parent) {
  vector<long long> vec;
  ans[v] = 0;
  for (typeof(g[v].begin()) it = g[v].begin(); it != g[v].end(); ++it) {
    int to = *it;
    if (to != parent) {
      k[to]--;
      Dfs(to, v);
      vec.push_back(ans[to]);
    }
  }
  sort((vec).begin(), (vec).end());
  reverse((vec).begin(), (vec).end());
  for (int i = 0; k[v] > 0 && i < vec.size(); ++i) {
    ans[v] += vec[i] + 2;
    k[v]--;
  }
  long long sum = 0;
  for (typeof(g[v].begin()) it = g[v].begin(); it != g[v].end(); ++it) {
    int to = *it;
    if (to != parent) sum += k[to];
  }
  long long tmp = min(1ll * k[v], sum);
  ans[v] += 2 * tmp;
  k[v] -= tmp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &k[i]);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int start;
  scanf("%d", &start);
  Dfs(start, -1);
  cout << ans[start] << endl;
  return 0;
}
