#include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<vector<int> > e;
vector<int> u;
pair<long long, long long> go(int x) {
  if (u[x] || !a[x]) return pair<long long, long long>();
  u[x] = 1;
  vector<pair<long long, long long> > b;
  for (int _n(e[x].size()), i(0); i < _n; i++) {
    b.push_back(go(e[x][i]));
    if (b.back() == pair<long long, long long>()) b.pop_back();
  }
  pair<long long, long long> res;
  res.first++;
  a[x]--;
  sort((b).begin(), (b).end());
  reverse((b).begin(), (b).end());
  for (int _n(b.size()), i(0); i < _n; i++) {
    if (a[x]) {
      res.first += b[i].first + 1;
      a[x]--;
    }
  }
  for (int _n(b.size()), i(0); i < _n; i++) {
    int v = min(a[x], (int)b[i].second);
    res.first += v * 2;
    a[x] -= v;
  }
  res.second = a[x];
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  a.resize(n);
  e.resize(n);
  u.resize(n);
  for (int _n(n), i(0); i < _n; i++) scanf("%d", &a[i]);
  int x, y;
  for (int _n(n - 1), i(0); i < _n; i++) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  int s;
  scanf("%d", &s);
  s--;
  a[s]++;
  pair<long long, long long> res = go(s);
  cout << res.first - 1 << endl;
  return 0;
}
