#include <bits/stdc++.h>
using namespace std;
int val[100010];
long long f[100010], cnt[100010], g[100010];
int n;
struct Edge {
  int a, b, next;
} edge[100010 * 2];
int num, head[100010];
void addedge(int a, int b) {
  edge[num].a = a;
  edge[num].b = b;
  edge[num].next = head[a];
  head[a] = num++;
}
bool cmp(long long x, long long y) { return x > y; }
void dfs(int now, int pre) {
  int next, i, j, k;
  int flag = 0, nn;
  for (i = head[now]; i != -1; i = edge[i].next) {
    next = edge[i].b;
    if (next == pre) continue;
    dfs(next, now);
    flag = 1;
  }
  f[now] = 1;
  cnt[now] = val[now] - 1;
  if (flag == 0) {
    return;
  }
  k = val[now] - 1;
  nn = 0;
  long long tmp = 0;
  for (i = head[now]; i != -1; i = edge[i].next) {
    j = edge[i].b;
    if (j == pre) continue;
    g[++nn] = f[j];
    tmp += cnt[j];
  }
  sort(g + 1, g + nn + 1, cmp);
  nn = min(nn, k);
  for (i = 1; i <= nn; i++) {
    f[now] += g[i] + 1;
    cnt[now] -= 1;
  }
  k -= nn;
  f[now] += min((long long)k, tmp) * 2;
  cnt[now] -= min((long long)k, tmp);
}
int main() {
  int i, j, k;
  while (scanf("%d", &n) != EOF) {
    num = 0;
    for (i = 0; i <= n; i++) {
      head[i] = -1;
    }
    for (i = 1; i <= n; i++) {
      scanf("%d", &val[i]);
    }
    for (i = 1; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      addedge(a, b);
      addedge(b, a);
    }
    int s;
    scanf("%d", &s);
    val[s]++;
    dfs(s, 0);
    cout << f[s] - 1 << endl;
  }
  return 0;
}
