def dfs(u): used[u] = True c = w = cw = ww = cww = 0 for v in e[u]: if not used[v]: # [c,w,cw,ww,cww] res = dfs(v) cww += res[4] + c * res[3] + w * res[2] + cw * res[1] + ww * res[0] if s[u] == 'c': cww += res[3] else: cw += res[0] ww += res[1] cww += res[2] + c * res[1] + w * res[0] c += res[0] w += res[1] cw += res[2] ww += res[3] if s[u] == 'c': c += 1 else: w += 1 return [c,w,cw,ww,cww] n = int(input()) s = input() e = [[] for i in range(n)] used = [False] * n for i in range(n-1): a, b = map(int,input().split(' ')) a -= 1 b -= 1 e[a].append(b) e[b].append(a) print(dfs(0)[4])