#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
pair<long long, int> dp[N];
vector<int> adj[N];
int n, s, k[N];
inline bool cmp(int u, int v) { return dp[u] > dp[v]; }
void dfs(int u, int par) {
  long long sum = 0, cnt = 0;
  for (int v : adj[u])
    if (v ^ par) {
      dfs(v, u);
      cnt += k[v];
    }
  sort(adj[u].begin(), adj[u].end(), cmp);
  dp[u] = {2 * min(cnt, k[u] - 1LL), k[u] - min(cnt, k[u] - 1LL) - 1};
  for (int i = 0, j = 0; i < adj[u].size(); i++)
    if (adj[u][i] ^ par) {
      sum += dp[adj[u][i]].first;
      cnt += dp[adj[u][i]].second - k[adj[u][i]];
      if (++j < k[u]) {
        long long x = min(cnt, k[u] - j - 1LL);
        dp[u] = max(dp[u], {sum + x + x + j + j, k[u] - x - j - 1});
      }
    }
}
inline void read_input() {
  cin >> n;
  for (int u = 0; u < n; u++) cin >> k[u];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[--u].push_back(--v);
    adj[v].push_back(u);
  }
  cin >> s;
  k[--s]++;
}
inline void solve() {
  dfs(s, s);
  cout << dp[s].first;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read_input(), solve();
  return 0;
}
