#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int oo = 0x80000000;
int n, S;
int w[N];
int fa[N];
int Q[N];
long long F[N];
vector<int> G[N];
void bfs() {
  int head = 0, tail = 1;
  Q[1] = S;
  fa[S] = 0;
  while (head != tail) {
    head++;
    int x = Q[head];
    int L = G[x].size();
    for (int i = 0; i < L; i++) {
      int y = G[x][i];
      if (fa[x] != y) {
        fa[y] = x;
        Q[++tail] = y;
      }
    }
  }
}
bool cmp(int i, int j) { return F[i] > F[j]; }
void solve() {
  for (int i = 1; i <= n; i++) F[i] = oo;
  for (int j = n; j >= 1; j--) {
    int low_limit = (j == 1) ? 0 : 1;
    int x = Q[j];
    int L = G[x].size();
    F[x] = 0;
    sort(G[x].begin(), G[x].end(), cmp);
    for (int i = 0; i < L; i++) {
      int y = G[x][i];
      if (fa[x] != y) {
        if (w[x] > low_limit && w[y] > 0) {
          F[x] += F[y] + 2;
          w[x]--;
          w[y]--;
        }
      }
    }
    for (int i = 0; i < L; i++) {
      int y = G[x][i];
      if (fa[x] != y) {
        if (w[x] > low_limit && w[y] > 0) {
          int delta = min(w[x] - low_limit, w[y]);
          F[x] += delta * 2;
          w[x] -= delta;
          w[y] -= delta;
        }
      }
    }
  }
  cout << F[S] << endl;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int x, y, i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  scanf("%d", &S);
  bfs();
  solve();
}
