#include <bits/stdc++.h>
using namespace std;
struct edge {
  int y;
  edge *next;
  edge(int y, edge *next) : y(y), next(next) {}
};
struct Stat {
  int x;
  edge *next;
  Stat(int x, edge *next) : x(x), next(next) {}
};
int n;
int num[100000];
int leftb[100000];
long long pro[100000];
int in_t[100000];
bool w[100000];
edge *a[100000];
long long solve(int x) {
  vector<Stat> st;
  st.push_back(Stat(x, a[x]));
  int cnt = 0;
  while (st.size() > 0) {
    Stat cur = st.back();
    w[cur.x] = 1;
    while (cur.next != 0 && w[cur.next->y]) cur.next = cur.next->next;
    st.pop_back();
    if (cur.next == 0) {
      int cc = cur.x;
      if (cc == x)
        leftb[cc] = num[cc], pro[cc] = 0;
      else
        leftb[cc] = num[cc] - 1, pro[cc] = 1;
      priority_queue<long long> pq;
      for (edge *i = a[cc]; i != 0; i = i->next)
        if (in_t[i->y] > in_t[cc]) pq.push(pro[i->y]);
      while (leftb[cc] > 0 && !pq.empty())
        pro[cc] += 1 + pq.top(), pq.pop(), leftb[cc] -= 1;
      for (edge *i = a[cc]; i != 0; i = i->next)
        if (in_t[i->y] > in_t[cc]) {
          int sub = min(leftb[cc], leftb[i->y]);
          pro[cc] += 2 * sub;
          leftb[cc] -= sub, leftb[i->y] -= sub;
        }
      continue;
    }
    st.push_back(Stat(cur.x, cur.next->next));
    st.push_back(Stat(cur.next->y, a[cur.next->y]));
    in_t[cur.next->y] = ++cnt;
  }
  return pro[x];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &num[i]);
  int x, y;
  for (int i = 0; i < n - 1; ++i)
    scanf("%d%d", &x, &y), --x, --y, a[x] = new edge(y, a[x]),
                                     a[y] = new edge(x, a[y]);
  int s;
  scanf("%d", &s);
  cout << solve(s - 1) << endl;
  return 0;
}
