N = input() S = raw_input() rinsetsu = [[] for i in xrange(N)] for _ in xrange(N-1): a, b = map(int, raw_input().split()) rinsetsu[a-1].append(b-1) rinsetsu[b-1].append(a-1) def dfs(start, root): cw = [0, 0] #stack = [(r, start) for r in rinsetsu[start]] stack = [(start, root)] while len(stack) > 0: n, prev = stack.pop() cw[0] += S[n] == 'c' cw[1] += S[n] == 'w' for nn in rinsetsu[n]: if nn != prev: stack.append((nn, n)) return cw ans = 0 for root in xrange(N): if S[root] != 'w': continue cw = [dfs(child, root) for child in rinsetsu[root]] for i in xrange(len(rinsetsu[root])): for j in xrange(i+1, len(rinsetsu[root])): ans += cw[i][0]*cw[j][1] + cw[j][0]*cw[i][1] print ans