#include <bits/stdc++.h>
using namespace std;
vector<int> d[100010];
long long k[100010];
long long dfs(int s, int p) {
  multiset<long long> r;
  long long fb = 0, res = 0;
  for (int i : d[s])
    if (i != p) {
      k[i]--;
      r.insert(-dfs(i, s));
      fb += k[i];
    }
  for (long long p : r)
    if (k[s]) {
      res -= p - 2;
      k[s]--;
    }
  fb = min(fb, k[s]);
  k[s] -= fb;
  return res + fb * 2;
}
int main() {
  int i, s, n, a, b;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> k[i];
  }
  for (i = 1; i < n; i++) {
    cin >> a >> b;
    d[a].push_back(b);
    d[b].push_back(a);
  }
  cin >> s;
  cout << dfs(s, 0);
  return 0;
}
