#include #include using namespace std; using int64 = long long; const int MAX_N = 100000; vector T[MAX_N]; int c[MAX_N], w[MAX_N], parent[MAX_N]; int N; string S; void dfs(int v, int par) { if (S[v] == 'c') c[v]++; else w[v]++; parent[v] = par; for (int to : T[v]) { if (to == par) continue; dfs(to, v); c[v] += c[to]; w[v] += w[to]; } } int main() { cin >> N >> S; for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--; b--; T[a].push_back(b); T[b].push_back(a); } dfs(0, -1); int64 ans = 0; for (int v = 0; v < N; v++) { if (S[v] != 'w') continue; int64 upc = c[0] - c[v], upw = w[0] - w[v]; int64 cumc = upc, cumw = upw; ans -= upc * upw; for (int to : T[v]) { if (to == parent[v]) continue; cumc += c[to]; cumw += w[to]; ans -= c[to] * w[to]; } ans += cumc * cumw; } cout << ans << endl; return 0; }