#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  string s;
  cin>>n>>s;
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  vector<Int> w(n,0),ww(n,0);
  {
    function<void(Int, Int)> dfs=
      [&](Int v,Int p){
        w[v]=s[v]=='w';
        for(Int u:G[v]){
          if(u==p) continue;
          dfs(u,v);
          w[v]+=w[u];
          ww[v]+=ww[u];
          if(s[v]=='w') ww[v]+=w[u];
        }        
      };
    dfs(0,-1);
  }
  Int ans=0,wa=0;
  for(Int i=0;i<n;i++) wa+=s[i]=='w';
  function<void(Int, Int, Int)> dfs=
    [&](Int v,Int p,Int x){
      //cout<<v<<":"<<x<<" "<<ww[v]<<endl;
      if(s[v]=='c') ans+=x+ww[v];
      for(Int u:G[v]){
        if(u==p) continue;
        if(s[v]=='c') dfs(u,v,x+(ww[v]-ww[u]));
        else dfs(u,v,x+(ww[v]-(w[v]-1)-ww[u])+(wa-w[v]));
      }
    };
  dfs(0,-1,0);
  cout<<ans<<endl;
  return 0;
}