#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 55;
long long a[100010];
long long memo[100010];
bool visited[100010];
vector<int> adj[100010];
long long res = 0;
bool comp(int u, int v) { return memo[u] > memo[v]; }
int start;
void dfs(int u) {
  vector<long long> child;
  child.clear();
  visited[u] = true;
  for (int(i) = 0; (i) < (adj[u].size()); (i)++) {
    int v = adj[u][i];
    if (!visited[v] && a[v] > 0) {
      a[v]--;
      memo[v]++;
      child.push_back(v);
      dfs(v);
    }
  }
  if (child.empty() && u != start) {
    memo[u] = 1;
    return;
  }
  sort((child).begin(), (child).end(), comp);
  for (int(i) = 0; (i) < (child.size()); (i)++) {
    long long cost = memo[child[i]];
    if (a[u] > 0) {
      a[u]--;
      memo[u] += cost + 1;
    }
  }
  for (int(i) = 0; (i) < (child.size()); (i)++) {
    int v = child[i];
    int mini = min(a[u], a[v]);
    a[u] -= mini;
    a[v] -= mini;
    memo[u] += 2 * mini;
  }
}
int main() {
  int n;
  cin >> n;
  for (int(i) = 0; (i) < (n + 2); (i)++) {
    adj[i].clear();
    a[i] = memo[i] = 0;
    visited[i] = false;
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    long long k;
    cin >> k;
    a[i + 1] = k;
  }
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  res = 0;
  cin >> start;
  dfs(start);
  cout << memo[start] << endl;
}
