#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(const T &a) {
  return a * a;
}
template <typename T>
inline int nread(vector<T> &a) {
  int n;
  cin >> n;
  a.clear();
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  return n;
}
template <typename T>
inline void nwread(int n, vector<T> &a) {
  a.clear();
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
}
int n;
vector<int> kb;
vector<vector<int> > gr;
vector<int> used;
long long int dfs(int u) {
  used[u] = 1;
  long long int res = 0, add = 0;
  vector<long long int> ress;
  for (int i = 0; i < gr[u].size(); i++) {
    int v = gr[u][i];
    if (used[v] || kb[v] == 0) continue;
    kb[v]--;
    ress.push_back(dfs(v));
    add += kb[v];
  }
  res += min(2LL * kb[u], (long long int)(2 * ress.size()));
  if (kb[u] >= ress.size()) {
    kb[u] -= min(kb[u], (int)ress.size());
    for (int i = 0; i < ress.size(); i++) res += ress[i];
    res += 2 * min(add, (long long int)kb[u]);
    kb[u] -= min(add, (long long int)kb[u]);
  } else {
    sort(ress.rbegin(), ress.rend());
    for (int i = 0; i < kb[u]; i++) res += ress[i];
    kb[u] = 0;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  kb.assign(n, 0);
  gr.assign(n, vector<int>());
  used.assign(n, 0);
  for (int i = 0; i < n; i++) scanf("%d", &kb[i]);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  int s;
  scanf("%d", &s);
  cout << dfs(s - 1);
}
