#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(const T& t) {
  return t * t;
}
template <class T>
T abs(const T& t) {
  return ((t > 0) ? (t) : (-t));
}
void initialize() {
  freopen("_.in", "r", stdin);
  freopen("_.out", "w", stdout);
}
struct Point {
  int x;
  int y;
  Point(int x_, int y_) : x(x_), y(y_) {}
};
const int MAX = (int)1e5 + 10;
int val[MAX];
long long lost[MAX];
const long long INF = (long long)1e9;
vector<int> reb[MAX];
long long run(int v, int p) {
  if (val[v] == 0) {
    return -INF;
  }
  vector<long long> r;
  long long l = 0;
  for (int i = 0; i < reb[v].size(); ++i) {
    int u = reb[v][i];
    if (u == p) continue;
    r.push_back(run(u, v));
    l += lost[u];
  }
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());
  long long res = 0;
  lost[v] = val[v];
  for (int i = 0; i < min(val[v] - 1, (int)r.size()); ++i) {
    if (r[i] > 0) {
      res += r[i] + 1;
      lost[v] -= 1;
    }
  }
  long long y = min(lost[v] - 1, l);
  res += 2 * y + 1;
  lost[v] -= y + 1;
  return res;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &val[i + 1]);
  }
  for (int i = 0; i + 1 < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    reb[u].push_back(v);
    reb[v].push_back(u);
  }
  int s;
  cin >> s;
  val[s] += 1;
  cout << run(s, -1) - 1;
  return 0;
}
