import java.util.*; import java.io.*; public class GuidGeneratorMN { static class Kattio extends PrintWriter { public Kattio(InputStream i) { super(new BufferedOutputStream(System.out)); this.r = new BufferedReader(new InputStreamReader(i)); } public Kattio(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); this.r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return this.peekToken() != null; } public int getInt() { return Integer.parseInt(this.nextToken()); } public double getDouble() { return Double.parseDouble(this.nextToken()); } public long getLong() { return Long.parseLong(this.nextToken()); } public String getWord() { return this.nextToken(); } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (this.token == null) { try { while (this.st == null || !this.st.hasMoreTokens()) { this.line = this.r.readLine(); if (this.line == null) { return null; } this.st = new StringTokenizer(this.line); } this.token = this.st.nextToken(); } catch (IOException e) { } } return this.token; } private String nextToken() { String ans = this.peekToken(); this.token = null; return ans; } } static class TrieNode { public int cnt; public TrieNode[] children; public TrieNode() { this.cnt = 0; this.children = new TrieNode[16]; Arrays.fill(this.children, null); } } static int convert(char c) { if (Character.isDigit(c)) { return (int) (c) - 48; } return (int) (c) - 87; } static ArrayList v = new ArrayList<>(); static ArrayList[] graph; static void dfs(int curr, int par, TrieNode node) { for (int neighbor : graph[curr]) { if (neighbor != par) { if (node.children[v.get(neighbor)] == null) { node.children[v.get(neighbor)] = new TrieNode(); } dfs(neighbor, curr, node.children[v.get(neighbor)]); } } } static void trieDfs(TrieNode node) { node.cnt++; for (var child : node.children) { if (child != null) { trieDfs(child); node.cnt += child.cnt; } } } public static void main(String[] args) throws IOException { Kattio io = new Kattio(System.in, System.out); int n = io.getInt(); String s = io.getWord(); for (int i = 0; i < s.length(); i++) { v.add(convert(s.charAt(i))); } graph = new ArrayList[n]; for (int i = 0; i < n; i++) { graph[i] = new ArrayList<>(); } for (int i = 0; i < n - 1; i++) { int u = io.getInt(), v = io.getInt(); graph[u - 1].add(v - 1); graph[v - 1].add(u - 1); } TrieNode root = new TrieNode(); for (int i = 0; i < n; i++) { if (root.children[v.get(i)] == null) { root.children[v.get(i)] = new TrieNode(); } dfs(i, -1, root.children[v.get(i)]); } trieDfs(root); io.println(root.cnt - 1); io.close(); } }