from itertools import * from bisect import * from collections import * from heapq import * import sys sys.setrecursionlimit(10 ** 6) def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def SI(): return sys.stdin.readline()[:-1] def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def LI1(): return list(map(int1, sys.stdin.readline().split())) p2D = lambda x: print(*x, sep="\n") dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] def main(): def dfs(u=0,pu=-1): for v in to[u]: if v==pu:continue dfs(v,u) w[u]+=w[v]+(s[v]=="w")*1 ww[u]+=ww[v]+(s[v]=="w")*w[v] def dfs2(u=0,pu=-1): for v in to[u]: if v==pu:continue wv=w[v]+(s[v]=="w")*1 ww[v]+=ww[u]-(ww[v]+(s[v]=="w")*w[v])+(w[u]-wv)*(s[u]=="w") w[v]+=w[u]-wv+(s[u]=="w") dfs2(v,u) n=II() s=SI() to=[[] for _ in range(n)] for _ in range(n-1): a,b=MI1() to[a].append(b) to[b].append(a) # 全方位DP # w[u]...頂点uのサブツリーのwの合計 # ww[u]...頂点uのサブツリーのwwの合計 w=[0]*n ww=[0]*n # 頂点0を根として子のサブツリーについて処理 dfs() #print(w) #print(ww) # 親方向のサブツリーを加算していく dfs2() #print(w) #print(ww) # 文字がcの頂点におけるwwの数がcwwの数 ans=0 for u in range(n): if s[u]=="w":continue ans+=ww[u] print(ans) main()