#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long beavers;
  vector<Node *> children;
};
static vector<vector<int> > edges;
static vector<Node> nodes;
static void connect(int i, int parent) {
  for (__typeof((edges[i]).begin()) it = (edges[i]).begin();
       it != (edges[i]).end(); ++it)
    if (*it != parent) {
      connect(*it, i);
      nodes[i].children.push_back(&nodes[*it]);
    }
}
static long long calc(Node *node) {
  vector<long long> counts;
  long long extra = 0;
  for (__typeof((node->children).begin()) it = (node->children).begin();
       it != (node->children).end(); ++it) {
    --(*it)->beavers;
    counts.push_back(1 + calc(*it));
    extra += (*it)->beavers;
  }
  sort(counts.rbegin(), counts.rend());
  while ((int((counts).size())) > node->beavers) counts.pop_back();
  long long res = 0;
  for (__typeof((counts).begin()) it = (counts).begin(); it != (counts).end();
       ++it) {
    --node->beavers;
    res += *it + 1;
  }
  extra = min(extra, node->beavers);
  res += 2 * extra;
  node->beavers -= extra;
  return res;
}
int main() {
  int N;
  cin >> N;
  edges.resize(N);
  nodes.resize(N);
  for (int n = 0; n < int(N); ++n) cin >> nodes[n].beavers;
  for (int n = 0; n < int(N - 1); ++n) {
    int i, j;
    cin >> i >> j;
    edges[i - 1].push_back(j - 1);
    edges[j - 1].push_back(i - 1);
  }
  int S;
  cin >> S;
  connect(S - 1, -1);
  cout << calc(&nodes[S - 1]) << endl;
}
