def dfs(u): used[u] = True c = w = cw = ww = cww = 0 for v in e[u]: if not used[v]: res = dfs(v) cww += res[4] + c * res[3] + w * res[2] + cw * res[1] + ww * res[0] if s[u] == 'w': cww += c * res[1] + w * res[0] c += res[0] w += res[1] cw += res[2] ww += res[3] if s[u] == 'c': c += 1 cww += ww else: cww += cw cw += c ww += w w += 1 print(u+1,c,w,cw,ww,cww) 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])