#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
long long n, dp[N], a[N], x, y, s;
vector<int> g[N];
void dfs(int x, int par) {
  dp[x] = 1, a[x]--;
  vector<long long> v;
  long long sum1 = 0;
  for (int i = 0; i < g[x].size(); i++) {
    if (g[x][i] != par) {
      dfs(g[x][i], x);
      v.push_back(dp[g[x][i]]);
      sum1 += a[g[x][i]];
    }
  }
  sort(v.begin(), v.end());
  for (int i = v.size() - 1; i >= 0; i--) {
    if (a[x]) {
      a[x]--;
      dp[x]++;
      dp[x] += v[i];
    }
  }
  dp[x] += min(a[x], sum1) * 2;
  a[x] -= min(a[x], sum1);
}
int main() {
  cin >> n;
  for (int i = 1; i < n + 1; i++) scanf("%I64d", &a[i]);
  ;
  for (int i = 1; i < n; i++) {
    scanf("%I64d%I64d", &x, &y);
    ;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cin >> s;
  a[s]++;
  dfs(s, 0);
  cout << --dp[s];
}
