public P077C() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        
        depth   = new int[N];
        beavers = new int[N];
        for (int i = 0; i < N; i++) {
            beavers[i] = sc.nextInt();
        }
        
        ArrayList<ArrayList<Integer>> adj = new ArrayList<ArrayList<Integer>>();
        for (int i = 0; i < N; i++) {
            adj.add(new ArrayList<Integer>());
        }
        for (int i = 0; i < N-1; i++) {
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;
            adj.get(u).add(v);
            adj.get(v).add(u);
        }
        
        int root = sc.nextInt() - 1;
        
        for (int i = 0; i < N; i++) {
            tree.add(new ArrayList<Integer>());
        }
        
        boolean[] visited = new boolean[N];
        java.util.Queue<Integer> queue = new ArrayDeque<Integer>();
        queue.add(root);
        visited[root] = true;
        depth[root] = 0;
        
        while (!queue.isEmpty()) {
            int u = queue.poll();
            for (int v: adj.get(u)) {
                if (visited[v]) continue;
                tree.get(u).add(v);
                queue.add(v);
                visited[v] = true;
                depth[v] = depth[u] + 1;
            }
        }
        
        // add 1 beaver to root will make it easier
        beavers[root]++;
        
        nodeInfo = new NodeInfo[N];
        
        solve();
        
        System.out.println(nodeInfo[root].eaten-1);
    }