from functools import reduce from math import factorial N = int(input()) S = input() G = {} H = {} for i in range(N-1): a,b = sorted(list(map(int, input().split(' ')))) if a-1 in G: G[a-1].append(b-1) elif a-1 not in G: G[a-1] = [b-1] if b-1 in H: H[b-1].append(a-1) else: H[b-1] = [a-1] for i in G: G[i] = sorted(G[i]) for i in H: H[i] = sorted(H[i]) def dfs(graph, node, started, ws, wss): if node not in graph: if S[node] == 'w': ws += 1 wss.append(ws) return if S[node] == 'w': ws += 1 else: if started: started = False else: wss.append(ws) return for n in graph[node]: dfs(graph, n, started, ws, wss) def nc2(n): if n < 2: return 0 f = factorial return f(n) // f(2) // f(n-2) forward = [] for i in range(len(S)): if S[i] == 'c': dfs(G, i, True, 0, forward) backward = [] for i in reversed(range(len(S))): if S[i] == 'c': dfs(H, i, True, 0, backward) print(reduce(lambda x,y: x+nc2(y), forward + backward, 0))