// Arup Guha
// 11/8/2025
// Solution to 2025 SER D1/D2 Problem D: GUID Generator
// Written during contest, commented later.

import java.util.*;

public class guidgenerator {

	public static long MOD1 = 1000000033;
	public static long MOD2 = 1000000087;
	public static long BASE = 19;
	public static char[] s;
	
	public static int n;
	public static ArrayList<Integer>[] g;
	
	public static HashSet<Long>[] sets;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		s = stdin.next().toCharArray();
		
		// Set up the graph.
		g = new ArrayList[n];
		for (int i=0; i<n; i++)
			g[i] = new ArrayList<Integer>();
			
		// Add the edges.
		for (int i=0; i<n-1; i++) {
			int u = stdin.nextInt()-1;
			int v = stdin.nextInt()-1;
			g[u].add(v);
			g[v].add(u);
		}
		
		// This is for hashing.
		sets = new HashSet[n+1];
		for (int i=0; i<n+1; i++)
			sets[i] = new HashSet<Long>();
			
		// Run DFS's from each starting node.
		for (int i=0; i<n; i++) {
			boolean[] used = new boolean[n];
			go(i, 0L, 0L, 0, used);
		}
			
		// Add up all set sizes.
		int res = 0;
		for (int i=1; i<=n; i++)
			res += sets[i].size();
		System.out.println(res);
		
	}
	
	// Conversion for hex and 1 to 16 for hashing.
	public static int val(char c) {
		if (c >= '0' && c <= '9')
			return c - '0' + 1;
		else
			return c - 'a' + 11;
	}
	
	// DFS with stored hashes.
	public static void go(int u, long h1, long h2, int k, boolean[] used) {
	
		// Mark this node.
		used[u] = true;
		
		// Update our hashes.
		h1 = (h1*BASE + val(s[u]))%MOD1;
		h2 = (h2*BASE + val(s[u]))%MOD2;
		
		// Add this to our set of unique strings.
		sets[k+1].add( (h1<<31) + h2 );
		
		// Recurse.
		for (Integer x: g[u]) {
			if (used[x]) continue;
			go(x, h1, h2, k+1, used);
		}
	
	}

}