#include <bits/stdc++.h>
using namespace std;
int n, root, tot;
int k[100010], head[100010];
struct edge {
  int to, next;
} e[100010 * 2];
void add(int x, int y) {
  e[++tot].to = y;
  e[tot].next = head[x];
  head[x] = tot;
}
pair<long long, long long> dfs(int x, int fa) {
  vector<long long> v;
  long long sum = 0, have_son = 0;
  for (int i = head[x]; i; i = e[i].next) {
    int vertex = e[i].to;
    if (vertex == fa) continue;
    have_son = 1;
    pair<long long, long long> son = dfs(vertex, x);
    sum += son.second;
    v.push_back(son.first);
  }
  if (!have_son) return make_pair(0, k[x] - 1);
  long long eat = 0, last = k[x] - (x == root ? 0 : 1);
  sort(v.begin(), v.end());
  for (int i = v.size() - 1; i >= 0 && last; i--, last--) eat += v[i] + 2;
  eat += 2 * min(last, sum);
  last -= min(last, sum);
  return make_pair(eat, last);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k[i]);
  }
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  scanf("%d", &root);
  cout << dfs(root, 0).first << endl;
  return 0;
}
