#include using namespace std; typedef long long ll; int N; ll ans; ll C[100000]; ll W[100000]; vector G[100000]; string S; void dfs1(int n, int p) { if(S[n] == 'c') C[n]++; else W[n]++; for(auto c : G[n]) { if(c == p) continue; dfs1(c, n); C[n] += C[c]; W[n] += W[c]; } } void dfs2(int n, int p) { if(S[n] == 'w') { ll csum = C[0], wsum = W[0]; for(auto c : G[n]) { ll cn = 0, wn = 0; if(c == p) { cn = csum - C[n]; wn = wsum - W[n]; } else { cn = C[c]; wn = W[c]; } ans += cn * (wsum - 1 - wn); //ans += wn * (csum - cn); } } for(auto c : G[n]) { if(c == p) continue; dfs2(c, n); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; cin >> S; for(int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); G[b].push_back(a); } dfs1(0, -1); dfs2(0, -1); cout << ans << endl; }