#include <bits/stdc++.h>
using namespace std;
int beavers[100005];
vector<int> tree[100005];
long long dp[100005];
long long used[100005];
bool vis[100005];
int rootId;
bool cmp(int id1, int id2) { return dp[id1] < dp[id2]; }
int TreeDp(int id) {
  if (vis[id]) return -1;
  vis[id] = 1;
  int i, sz = tree[id].size();
  int childrenCt = 0;
  vector<int> childrenBuff;
  for (i = 0; i < sz; i++) {
    int childId = tree[id][i];
    if (TreeDp(childId) > 0) {
      childrenBuff.push_back(childId);
      childrenCt++;
    }
  }
  sort(childrenBuff.begin(), childrenBuff.end(), cmp);
  int availableBeavers = beavers[id];
  if (id != rootId) availableBeavers--;
  if (availableBeavers < 0) {
    dp[id] = 0;
    used[id] = 0;
  } else {
    if (id != rootId) {
      dp[id] = 1;
      used[id] = 1;
    } else {
      dp[id] = 0;
      used[id] = 0;
    }
    sz = availableBeavers;
    for (i = childrenCt - 1; i >= 0 && sz > 0; i--, sz--) {
      dp[id] = dp[id] + (long long)(dp[childrenBuff[i]] + 1);
      used[id]++;
    }
    for (i = childrenCt - 1; i >= 0 && sz > 0; i--) {
      int childId = childrenBuff[i];
      int tmp = sz < (beavers[childId] - used[childId])
                    ? sz
                    : (beavers[childId] - used[childId]);
      dp[id] = dp[id] + (long long)tmp * 2;
      used[id] += tmp;
      sz -= tmp;
    }
  }
  return 1;
}
int main() {
  int i, n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &beavers[i]);
  }
  for (i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  scanf("%d", &rootId);
  rootId--;
  memset(vis, 0, sizeof(vis));
  TreeDp(rootId);
  cout << dp[rootId] << endl;
  return 0;
}
