#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; vector > makeTree(const vector &u, const vector &v) { int V = (int)u.size() + 1; vector > tree(V), graph(V); for(int i = 0; i < V - 1; ++i) { graph[u[i]].push_back(v[i]); graph[v[i]].push_back(u[i]); } queue > Q; Q.push(make_pair(0, -1)); while(!Q.empty()) { int cur, pre; tie(cur, pre) = Q.front(); Q.pop(); for(auto &to : graph[cur]) if(to != pre) { tree[cur].push_back(to); Q.push(make_pair(to, cur)); } } return tree; } const int MA = 100010; int N; char S[100010]; vector G; ll dp[100010][4], ww[MA], wc[MA], nw[MA], nc[MA]; ll dfs(int u) { if(S[u] == 'w')nw[u]++; if(S[u] == 'c')nc[u]++; ll res = 0; each(v, G[u]) { res += dfs(v); nw[u] += nw[v]; nc[u] += nc[v]; ww[u] += ww[v]; wc[u] += wc[v]; if(S[u] == 'w') { ww[u] += nw[v]; wc[u] += nc[v]; } } each(v, G[u]) { if(S[u]=='c') res += ww[v]; else if(S[u] == 'w')res += wc[v]; } ll sumW = nw[u] - !!(S[u] == 'w'); ll sumC = nc[u] - !!(S[u] == 'c'); if(S[u]=='w')each(v, G[u]) { ll numW = sumW - nw[v], numC = nc[v]; res += numW*numC; } each(v, G[u]) { res += (sumW - nw[v])*wc[v]; } each(v, G[u]) { res += ww[v] * (sumC-nc[v]); } return res; } int main(){ cin >> N; scanf("%s", S); vi A(N - 1), B(N - 1); rep(i, N - 1) { int a, b; scanf("%d%d", &a, &b); A[i] = a - 1; B[i] = b - 1; } G = makeTree(A, B); ll ans = dfs(0); cout << ans << endl; }