N = int(input()) S = input() G = [ [] for _ in range(len(S))] for i in range(N-1): a,b = sorted(list(map(int, input().split(' ')))) G[a-1].append(b-1) G[b-1].append(a-1) tc = 0 tw = 0 for s in S: if s == 'c': tc += 1 else: tw += 1 cc = [0 for _ in range(len(S))] cw = [0 for _ in range(len(S))] count = 0 def dfs(current, parent): global count if S[current] == 'c': cc[current] += 1 else: cw[current] += 1 for adj in G[current]: if adj != parent: dfs(adj, current) cc[current] += cc[adj] cw[current] += cw[adj] if S[current] == 'w': count += cc[adj] * (tw-1-cw[adj]) if parent != -1 and S[current] == 'w': count += (tc-cc[current]) * (cw[current]-1) dfs(0, -1) print(count)