import java.util.*;

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

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

        color = sc.next().toCharArray();
        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();
            int v = sc.nextInt();
            tree[u].add(v);
            tree[v].add(u);
        }

        long res = Long.MAX_VALUE;
        for (int root = 1; root <= n; root++) {
            char targetColor = color[root - 1];
            visited = new boolean[n + 1];
            long cost = dfs(root, -1, targetColor);
            res = Math.min(res, cost);
        }

        System.out.println(res);
    }

    // 计算以当前节点为根的子树变为目标颜色的总代价
    static long dfs(int u, int parent, char targetColor) {
        visited[u] = true;
        long cost = 0;
        if (color[u - 1] != targetColor) {
            cost += weight[u];
        }
        for (int v : tree[u]) {
            if (v != parent && !visited[v]) {
                cost += dfs(v, u, targetColor);
            }
        }
        return cost;
    }
}
