import sys from collections import deque input = sys.stdin.readline N = int(input()) S = input() T = [[] for _ in range(N)] for _ in range(N - 1): a, b = (int(x) - 1 for x in input().split()) T[a].append(b) T[b].append(a) # dfs dfs_order = [] parent = [None] * N d = deque([0]) nonvisited = [True] * N nonvisited[0] = False while d: v = d.pop() dfs_order.append(v) for x in T[v]: if nonvisited[x]: d.append(x) parent[x] = v nonvisited[x] = False Csum, Wsum = S.count('c'), S.count('w') # 子から親へ C, W = [0] * N, [0] * N ans = 0 for v in reversed(dfs_order): if S[v] == 'c': C[v] += 1 else: # S[v] == 'w' W[v] += 1 for child in T[v]: if child == parent[v]: continue C[v] += C[child] W[v] += W[child] if S[v] == 'w': ans += W[child] * (Csum - C[child]) if S[v] == 'w': ans += C[v] * (Wsum - W[v]) print(ans)