#include <bits/stdc++.h>
using namespace std;
struct node {
  int v;
  vector<int> son;
} v[100005];
long long dfs(int x, int p) {
  int n = v[x].v - (p != -1);
  long long dist = 0;
  vector<long long> sonv;
  if (n > 0) {
    long long leftn = 0;
    for (int i = 0; i < v[x].son.size(); ++i)
      if (v[x].son[i] != p) {
        long long t = dfs(v[x].son[i], x);
        if (t) sonv.push_back(t);
        leftn += v[v[x].son[i]].v;
      }
    sort(sonv.begin(), sonv.end());
    for (int i = sonv.size(); i > 0 && n > 0; --i, --n, --leftn)
      dist += sonv[i - 1] + 2;
    int minv = n;
    if (minv > leftn) minv = leftn;
    dist += 2 * minv;
    n -= minv;
  }
  v[x].v = n + (p != -1);
  return dist;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &v[i].v);
  for (int i = 1; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a - 1].son.push_back(b - 1);
    v[b - 1].son.push_back(a - 1);
  }
  int s;
  scanf("%d", &s);
  cout << dfs(s - 1, -1);
  return 0;
}
