#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
struct Edge {
  int v, next;
} edge[1000000];
int head[100010];
int pos;
void insert(int x, int y) {
  edge[pos].v = y;
  edge[pos].next = head[x];
  head[x] = pos++;
}
long long mm[100010];
long long lef[100010];
bool vis[100010];
void dfs(int now, int pre) {
  long long total = 0;
  vector<long long> ooxx;
  long long add = 0;
  vis[now] = true;
  if (lef[now] == 0) return;
  if (pre != -1) lef[now]--;
  for (int i = head[now]; i; i = edge[i].next) {
    int v = edge[i].v;
    if (v == pre) continue;
    if (!vis[v]) dfs(v, now);
    if (lef[v] == 0) continue;
    if (mm[v] != 0) {
      ooxx.push_back(mm[v]);
      lef[v]--;
    }
    add += lef[v];
  }
  int len = ooxx.size();
  sort(ooxx.begin(), ooxx.end(), cmp);
  for (int i = 0; i < len && lef[now]; i++) {
    long long s = ooxx[i];
    lef[now]--;
    total += s + 2;
  }
  long long pp;
  if (lef[now] < add)
    pp = lef[now];
  else
    pp = add;
  total += 2 * pp;
  mm[now] = total;
  lef[now] -= pp;
  lef[now]++;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &lef[i]);
  memset(head, 0, sizeof(head));
  pos = 1;
  int x, y;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    insert(x, y);
    insert(y, x);
  }
  memset(mm, 0, sizeof(mm));
  memset(vis, false, sizeof(vis));
  int src;
  scanf("%d", &src);
  dfs(src, -1);
  printf("%I64d\n", mm[src]);
  return 0;
}
