#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 100 + 10;
int k[MAXN], start;
vector<int> ng[MAXN];
long long dfs(int x, int par) {
  vector<pair<long long, int> > tmp;
  for (int i = 0; i < ng[x].size(); i++) {
    int u = ng[x][i];
    if (u == par) continue;
    tmp.push_back(pair<long long, int>(dfs(u, x), u));
  }
  sort(tmp.begin(), tmp.end());
  reverse(tmp.begin(), tmp.end());
  long long ret = 0;
  for (int i = 0; i < (int)tmp.size() && k[x] > (x != start); i++) {
    ret += tmp[i].first + 2;
    k[x]--;
    k[tmp[i].second]--;
  }
  for (int i = 0; i < ng[x].size(); i++) {
    int u = ng[x][i];
    if (u == par) continue;
    if (k[x] > (x != start) && k[u]) {
      long long val = min(k[u], k[x] - (x != start));
      k[x] -= val, k[u] -= val, ret += 2ll * val;
    }
  }
  return ret;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> k[i];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    ng[x].push_back(y);
    ng[y].push_back(x);
  }
  cin >> start;
  start--;
  cout << dfs(start, -1) << endl;
  return 0;
}
