import sys input = sys.stdin.readline N = int(input()) S = list(input().rstrip()) allc, allw = 0, 0 for i in range(N): S[i] = int(S[i] == "w") allw = sum(S) allc = N - allw G = [[] for i in range(N)] for i in range(N - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 G[a].append(b) G[b].append(a) def non_rec_dfs(s): stack = [] stack.append(s) par = [-1] * N sz = [[0] * 2 for i in range(N)] for i in range(N): sz[i][S[i]] += 1 ans = 0 while stack: u = stack.pop() if u >= 0: stack.append(~u) for v in G[u]: if v == par[u]: continue par[v] = u stack.append(v) else: u = ~u if S[u]: ans += allc * (allw - 1) noww, nowc = allw, allc for v in G[u]: if v == par[u]: continue ans -= sz[v][0] * sz[v][1] nowc -= sz[v][0] noww -= sz[v][1] ans -= nowc * (noww - 1) if par[u] != -1: sz[par[u]][0] += sz[u][0] sz[par[u]][1] += sz[u][1] return ans print(non_rec_dfs(0))