#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
vector<int> G[MaxN];
int N, Root, Size[MaxN], Father[MaxN], Left[MaxN];
long long DP[MaxN];
void SolveDP(int X) {
  DP[X] = 0, Left[X] = Size[X];
  if (Size[X] == 0) return;
  vector<long long> SonDP;
  for (vector<int>::iterator Y = G[X].begin(); Y != G[X].end(); ++Y)
    if (*Y != Father[X] && Size[*Y] >= 0) SonDP.push_back(DP[*Y]);
  sort(SonDP.rbegin(), SonDP.rend());
  for (vector<long long>::iterator Son = SonDP.begin();
       Son != SonDP.end() && Left[X] > 0; ++Son)
    DP[X] += 1 + (*Son), ++DP[X], --Left[X];
  for (vector<int>::iterator Y = G[X].begin(); Y != G[X].end() && Left[X] > 0;
       ++Y)
    DP[X] += 2 * min(Left[X], Left[*Y]), Left[X] -= min(Left[X], Left[*Y]);
}
void DFS(int X) {
  for (vector<int>::iterator Y = G[X].begin(); Y != G[X].end(); ++Y) {
    if (*Y != Father[X]) {
      Father[*Y] = X;
      DFS(*Y);
    }
  }
  SolveDP(X);
}
void Read() {
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> Size[i];
    --Size[i];
  }
  for (int i = 1; i < N; ++i) {
    int X, Y;
    cin >> X >> Y;
    G[X].push_back(Y), G[Y].push_back(X);
  }
  cin >> Root;
  ++Size[Root];
}
void Print() { cout << DP[Root] << "\n"; }
int main() {
  Read();
  DFS(Root);
  Print();
  return 0;
}
