import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) def dfs(cur, prev=-1): global res cs = [] ws = [] for nn in adj_list[cur]: if nn != prev: c, w = dfs(nn, cur) cs.append(c) ws.append(w) if S[cur] == 'c': return sum(cs)+1, sum(ws) elif S[cur] == 'w': cs.append(total_c-sum(cs)) ws.append(total_w-sum(ws)-1) sum_w = sum(ws) for c, w in zip(cs, ws): res += c*(sum_w-w) return sum(cs[:-1]), sum_w-ws[-1]+1 N = int(input()) S = input() total_c = S.count('c') total_w = S.count('w') adj_list = [[] for _ in range(N)] for _ in range(N-1): a, b = map(int, input().split()) adj_list[a-1].append(b-1) adj_list[b-1].append(a-1) res = 0 dfs(0) print(res)