#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, next;
} edge[100100 << 1];
int head[100100], tot;
void addedge(int u, int v) {
  edge[tot].to = v;
  edge[tot].next = head[u];
  head[u] = tot++;
}
void init() {
  memset(head, -1, sizeof(head));
  tot = 0;
}
int a[100100], n;
long long dp[100100], lef[100100];
vector<long long> g[100100], g2[100100];
bool cmp(int x, int y) { return x > y; }
void dfs(int u, int pre) {
  dp[u] = 1;
  lef[u] = a[u] - 1;
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == pre) continue;
    dfs(v, u);
    g[u].push_back(dp[v]);
    g2[u].push_back(lef[v]);
  }
  sort(g[u].begin(), g[u].end(), cmp);
  sort(g2[u].begin(), g2[u].end(), cmp);
  for (int i = 0; i < min((int)g[u].size(), a[u] - 1); ++i) {
    dp[u] += g[u][i] + 1;
    --lef[u];
  }
  int now = 0;
  while (lef[u] > 0 && now < g2[u].size()) {
    if (lef[u] < g2[u][now]) {
      dp[u] += lef[u] * 2LL;
      lef[u] = 0;
      break;
    }
    dp[u] += g2[u][now] * 2LL;
    lef[u] -= g2[u][now];
    now++;
  }
  lef[u] = max(lef[u], 0LL);
}
int main() {
  while (~scanf("%d", &n)) {
    init();
    int u, v;
    for (int i = 1; i <= n; ++i) {
      g[i].clear();
      g2[i].clear();
    }
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i < n; ++i) {
      scanf("%d%d", &u, &v);
      addedge(u, v);
      addedge(v, u);
    }
    int st;
    scanf("%d", &st);
    ++a[st];
    dfs(st, -1);
    printf("%lld\n", dp[st] - 1);
  }
  return 0;
}
