#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int bev[100100], N;
vector<long long> adj[100100];
pair<long long, long long> rek(int n, int par) {
  long long ones = 0;
  vector<long long> ch = vector<long long>();
  for (int i = (0); i < (int((adj[n]).size())); i++) {
    int to = adj[n][i];
    if (to == par) continue;
    if (bev[to]) {
      --bev[to];
      pair<long long, long long> tmp = rek(to, n);
      ones += tmp.second;
      ch.push_back(tmp.first);
    }
  }
  long long res = 0;
  sort((ch).begin(), (ch).end());
  for (int i = int(int((ch).size())) - 1; i >= (0); i--) {
    if (bev[n] == 0) break;
    bev[n]--;
    res += ch[i] + 2;
  }
  ones = min(ones, (long long)bev[n]);
  res += 2 * ones;
  bev[n] -= ones;
  return pair<long long, long long>(res, bev[n]);
}
int main() {
  scanf("%d", &N);
  for (int i = (0); i < (N); i++) adj[i].clear();
  for (int i = (1); i < (N + 1); i++) scanf("%d", bev + i);
  for (int i = (1); i < (N); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int s;
  scanf("%d", &s);
  cout << rek(s, -1).first << endl;
  return 0;
}
