#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> G[N];
long long val[N];
long long dp[N];
void treeDP(int rt, int f) {
  for (auto& v : G[rt]) {
    if (v != f) treeDP(v, rt);
  }
  vector<long long> tmp;
  for (auto& v : G[rt]) {
    if (v != f) tmp.push_back(dp[v]);
  }
  sort(tmp.begin(), tmp.end(), greater<long long>());
  for (auto x : tmp) {
    if (val[rt]) dp[rt] += x + 2, --val[rt];
  }
  for (auto& v : G[rt]) {
    if (v != f && val[rt] && val[v]) {
      long long p = min(val[rt], val[v]);
      val[rt] -= p, dp[rt] += 2 * p;
    }
  }
}
int main() {
  int n, a, b;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", val + i), --val[i];
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int root;
  scanf("%d", &root);
  ++val[root];
  treeDP(root, -1);
  printf("%lld\n", dp[root]);
}
