#include <bits/stdc++.h>
using namespace std;
int n;
int root;
vector<vector<int> > adj;
vector<vector<int> > child;
vector<int> anc;
pair<unsigned long long, unsigned long long> dp[100000 + 10];
int bu[100000 + 10];
int n_b[100000 + 10];
bool work[100000 + 10];
ostream& operator<<(ostream& os, const pair<int, int>& p) {
  return os << "(" << (p).first << ", " << (p).second << ")";
}
bool cmp(const int& a, const int& b) { return dp[a] > dp[b]; }
void test_case() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", n_b + i);
  adj.resize(n);
  anc.assign(n, -1);
  child.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    adj[x].push_back(y), adj[y].push_back(x);
  }
  scanf("%d", &root);
  --root;
  {
    queue<int> q;
    q.push(root);
    anc[root] = root;
    while (q.size()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < adj[u].size(); ++i) {
        int v = adj[u][i];
        if (v != anc[u]) q.push(v), anc[v] = u, child[u].push_back(v);
      }
    }
  }
  {
    for (int i = 0; i < n; ++i) work[i] = false;
    queue<int> q;
    q.push(root);
    work[root] = true;
    int k = n;
    while (q.size()) {
      int u = q.front();
      q.pop();
      bu[--k] = u;
      for (int i = 0; i < child[u].size(); ++i) q.push(child[u][i]);
    }
    assert(k == 0);
  }
  n_b[root]++;
  for (int i = 0; i < n; ++i) {
    int x = bu[i];
    if (n_b[x] == 0) {
      dp[x] = make_pair(0, 0);
      continue;
    }
    sort(child[x].begin(), child[x].end(), cmp);
    if (n_b[x] - 1 > child[x].size()) {
      unsigned long long sum1 = 0;
      for (int i = 0; i < child[x].size(); ++i) sum1 += (dp[child[x][i]]).first;
      unsigned long long sum2 = 0;
      for (int i = 0; i < child[x].size(); ++i)
        sum2 += (dp[child[x][i]]).second;
      (dp[x]).first = 1 + child[x].size() + sum1;
      (dp[x]).second = n_b[x] - 1 - child[x].size();
      int spend = min((dp[x]).second, sum2);
      (dp[x]).first += 2 * spend;
      (dp[x]).second -= spend;
    } else {
      (dp[x]).first = n_b[x];
      for (int i = 0; i < n_b[x] - 1; ++i)
        (dp[x]).first += (dp[child[x][i]]).first;
      (dp[x]).second = 0;
    }
  }
  cout << ((dp[root]).first - 1) << endl;
}
int main() {
  test_case();
  return 0;
}
