#include <bits/stdc++.h>
using namespace std;
struct node {
  int t;
  struct node *next;
};
struct node *tree[100005], edges[2 * 100005], *start;
void add(int s, int t) {
  start->t = t;
  start->next = tree[s];
  tree[s] = start++;
}
int n, vis[100005];
long long dp[100005], lefts[100005];
void treedp(int root) {
  vis[root] = 1;
  struct node *cur = tree[root];
  priority_queue<long long> que;
  while (!que.empty()) que.pop();
  lefts[root]--;
  dp[root] = 1;
  long long sum = 0;
  while (cur) {
    if (!vis[cur->t] && lefts[root]) {
      treedp(cur->t);
      que.push(dp[cur->t]);
      sum += lefts[cur->t];
    }
    cur = cur->next;
  }
  while (lefts[root] && !que.empty()) {
    dp[root] += que.top() + 1;
    que.pop();
    lefts[root]--;
  }
  if (lefts[root] >= sum) {
    dp[root] += 2 * sum;
    lefts[root] -= sum;
  } else {
    dp[root] += 2 * lefts[root];
    lefts[root] = 0;
  }
}
int main() {
  int i, j, a, b;
  while (scanf("%d", &n) != EOF) {
    memset(tree, 0, sizeof(tree));
    memset(vis, 0, sizeof(vis));
    start = edges;
    for (i = 1; i <= n; i++) {
      scanf("%I64d", &lefts[i]);
    }
    for (i = 1; i < n; i++) {
      scanf("%d%d", &a, &b);
      add(a, b);
      add(b, a);
    }
    int root;
    scanf("%d", &root);
    lefts[root]++;
    treedp(root);
    printf("%I64d\n", dp[root] - 1);
  }
  return 0;
}
