#include <bits/stdc++.h>
namespace OI {
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char c;
  while (!isdigit(c = getchar()))
    if (c == '-') f = -1;
  do {
    x = (x << 3) + (x << 1) + (c ^ 48);
  } while (isdigit(c = getchar()));
  x *= f;
}
template <class T>
void pt(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) pt(x / 10);
  putchar(x % 10 ^ 48);
}
}  // namespace OI
using namespace OI;
using namespace std;
const int N = 1e5 + 5;
int n, v[N], rt;
vector<int> G[N];
pair<long long, long long> dfs(int x, int fa) {
  if (G[x].size() == 1 && x != rt)
    return pair<long long, long long>{0, v[x] - 1};
  vector<pair<long long, long long> > Vec;
  long long sum = 0, eat = 0, las = v[x];
  for (auto it : G[x])
    if (it != fa) {
      pair<long long, long long> tmp = dfs(it, x);
      sum += tmp.second;
      Vec.push_back(tmp);
    }
  if (x != rt) las--;
  sort(Vec.begin(), Vec.end());
  for (int i = Vec.size() - 1; las > 0 && i >= 0; las--, i--)
    eat += Vec[i].first + 2;
  eat += 2 * min(las, sum);
  las -= min(las, sum);
  return pair<long long, long long>{eat, las};
}
int main() {
  rd(n);
  for (int i = 1; i <= n; i++) rd(v[i]);
  for (int i = 1, x, y; i < n; i++)
    rd(x), rd(y), G[x].push_back(y), G[y].push_back(x);
  rd(rt);
  pt(dfs(rt, 0).first);
  return 0;
}
