import sys sys.setrecursionlimit(1000000) n = int(input()) s = input() G = [[] for _ in range(n)] for m in range(n-1): x, y = [int(i) for i in input().split()] x -= 1 y -= 1 G[x].append(y) G[y].append(x) nc = s.count('c') nw = s.count('w') dp1 = [[0,0] for _ in range(n)] def dfs1(u, p): dp1[u][0] = 1 if s[u] == 'c' else 0 dp1[u][1] = 1 if s[u] == 'w' else 0 res = 0 for to in G[u]: if to == p: continue res += dfs1(to, u) dp1[u][0] += dp1[to][0] dp1[u][1] += dp1[to][1] if s[u] == 'w': res += dp1[to][0] * (nw - dp1[to][1] - 1) if s[u] == 'w': res += (nc - dp1[u][0]) * (dp1[u][1] - 1) return res print(dfs1(0,-1))