#include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,l,r) for(int i=(l);i<=(r);i++) #define per(i,r,l) for(int i=(r);i>=(l);i--) #define all(vc) vc.begin(),vc.end() #define sz(vc) ((int)vc.size()) #define pb push_back #define fi first #define se second #define x0 __x00 #define y0 __y00 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; const int N=1e5+5; string s; int n,w,c,f[N],g[N]; vectorG[N]; ll ans; void dfs(int x,int fa){ f[x]+=s[x]=='w'; g[x]+=s[x]=='c'; for(auto to:G[x]){ if(to==fa)continue; dfs(to,x); f[x]+=f[to],g[x]+=g[to]; } if(s[x]=='c')return; for(auto to:G[x]){ if(to==fa)continue; ans+=1ll*g[x]*(w-f[to]-1); } ans+=1ll*(f[x]-1)*(c-g[x]); } int main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n>>s; s=' '+s; rep(i,2,n){ int u,v;cin>>u>>v; G[u].pb(v);G[v].pb(u); } rep(i,1,n)w+=s[i]=='w',c+=s[i]=='c'; dfs(1,-1); cout<