#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
int a[100100];
int was[100100];
int root;
long long dfs(int v) {
  was[v] = 1;
  vector<pair<long long, int> > q;
  long long res = 0;
  for (int i = (0); i < (g[v].size()); ++i) {
    int to = g[v][i];
    if (was[to] == 0) {
      a[to]--;
      q.push_back(make_pair(dfs(to), to));
    }
  }
  sort(q.rbegin(), q.rend());
  int p = a[v];
  for (int i = (0); i < (q.size()); ++i) {
    int to = q[i].second;
    if (p > 0) {
      res += q[i].first;
      res += 2;
      p--;
    }
  }
  for (int i = (0); i < (q.size()); ++i) {
    int to = q[i].second;
    if (p > 0) {
      int k = ((p < a[to]) ? (p) : (a[to]));
      res += k + k;
      p -= k;
      a[to] -= k;
    }
  }
  a[v] = p;
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
  g.resize(n);
  for (int i = (0); i < (n - 1); ++i) {
    int aa, bb;
    scanf("%d%d", &aa, &bb);
    aa--;
    bb--;
    g[aa].push_back(bb);
    g[bb].push_back(aa);
  }
  int root;
  cin >> root;
  root--;
  long long res = dfs(root);
  cout << res << endl;
  return 0;
}
