#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair P; ll ctc[100000], ctw[100000]; bool used[100000]; vector g[100000]; int n; string s; void dfs(int x){ used[x]=1; if(s[x]=='c') ctc[x]++; else ctw[x]++; for(auto y:g[x]){ if(used[y]) continue; dfs(y); ctc[x]+=ctc[y]; ctw[x]+=ctw[y]; } } ll ans; void dfs2(int x){ used[x]=1; ll sw=ctw[0]-1; for(auto y:g[x]){ if(used[y]) continue; if(s[x]=='w'){ ans+=((sw-ctw[y])*ctc[y]); } dfs2(y); } if(s[x]=='w') ans+=((ctc[0]-ctc[x])*(ctw[x]-1)); } int main() { cin>>n; cin>>s; for(int i=0; i>a>>b; a--; b--; g[a].push_back(b); g[b].push_back(a); } dfs(0); fill(used, used+n, 0); dfs2(0); cout<