import java.util.*;

public class Main {
    static int n;
    static char[] color;
    static long[] weight;
    static List<Integer>[] tree;

    static long dfs(int u, int parent, char targetColor) {
        long cost = 0;
        if (color[u] != targetColor) cost += weight[u];
        for (int v : tree[u]) {
            if (v != parent) {
                cost += dfs(v, u, targetColor);
            }
        }
        return cost;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        color = (" " + sc.next()).toCharArray(); // 1-index
        weight = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            weight[i] = sc.nextLong();
        }

        tree = new ArrayList[n + 1];
        for (int i = 1; i <= n; i++) tree[i] = new ArrayList<>();
        for (int i = 1; i < n; i++) {
            int u = sc.nextInt(), v = sc.nextInt();
            tree[u].add(v);
            tree[v].add(u);
        }

        long minCost = Long.MAX_VALUE;

        // 枚举每个点作为根节点
        for (int root = 1; root <= n; root++) {
            char target = color[root];
            long cost = dfs(root, -1, target);
            minCost = Math.min(minCost, cost);
        }

        System.out.println(minCost);
    }
}
