#include <bits/stdc++.h>
using namespace std;
vector<int> tree[100000];
long long b[100000];
int v[100000];
long long ost[100000];
long long kol[100000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    v[i] = 0;
    kol[i] = -1;
    ost[i] = -1;
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    tree[x].push_back(y);
    tree[y].push_back(x);
    v[x]++;
    v[y]++;
  }
  int s;
  cin >> s;
  s--;
  queue<int> q;
  for (int i = 0; i < n; i++)
    if (v[i] == 1 && i != s || v[i] == 0 && i == s) q.push(i);
  while (!q.empty()) {
    int cur = q.front();
    kol[cur] = ost[cur] = 0;
    q.pop();
    int r = -1;
    priority_queue<long long> w;
    long long co = 0;
    for (int i = 0; i < tree[cur].size(); i++) {
      int e = tree[cur][i];
      if (kol[e] != -1) {
        co += ost[e];
        w.push(kol[e]);
      } else
        r = e;
    }
    if (b[cur]) {
      if (cur != s) {
        b[cur]--;
        kol[cur]++;
      }
      while (b[cur] && !w.empty()) {
        kol[cur] += w.top() + 1;
        b[cur]--;
        w.pop();
      }
      if (b[cur]) {
        if (b[cur] > co) {
          kol[cur] += 2 * co;
          b[cur] -= co;
        } else {
          kol[cur] += 2 * b[cur];
          b[cur] = 0;
        }
      }
      ost[cur] = b[cur];
    }
    v[r]--;
    if (v[r] == 1 && r != s || v[r] == 0 && r == s) q.push(r);
  }
  cout << kol[s];
  return 0;
}
