#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
int n;
int a[111111];
vector<int> v[111111];
int s;
pair<long long, long long> go(int ver, int par = -1) {
  vector<pair<long long, long long> > vv;
  for (int i(0); i < (v[ver].size()); i++)
    if (v[ver][i] != par) vv.push_back(go(v[ver][i], ver));
  if (vv.size() == 0) return pair<long long, long long>(0, a[ver]);
  sort((vv).begin(), (vv).end());
  reverse(vv.begin(), vv.end());
  long long total = 0;
  for (int i(0); i < (vv.size()); i++)
    if (a[ver] >= 1) {
      a[ver]--;
      total += 1 + 1 + vv[i].first;
    }
  for (int i(0); i < (vv.size()); i++) {
    int z = min((int)vv[i].second, a[ver]);
    total += 2 * z;
    a[ver] -= z;
  }
  return pair<long long, long long>(total, a[ver]);
}
int main() {
  cin >> n;
  for (int i(0); i < (n); i++) scanf("%d", a + i);
  for (int i(0); i < (n - 1); i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--, y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  cin >> s;
  s--;
  for (int i(0); i < (n); i++)
    if (i != s) a[i]--;
  cout << go(s).first << endl;
  return 0;
}
