#include #include using namespace std; using namespace atcoder; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() #define ALLR(v) (v).rbegin(),(v).rend() #define fi first #define se second #define PB push_back #define EB emplace_back template using PQ = priority_queue; template using QP = priority_queue,greater>; templatevoid debug(const T &v,ll h,ll w){for(ll i=0;ivoid debug(const T &v,ll n){for(ll i=0;ivoid debug(const vector&v){debug(v,v.size());} templatevoid debug(const vector>&v){for(auto &vv:v)debug(vv,vv.size());} templatevoid debug(stack st){while(!st.empty()){cerr<void debug(queue st){while(!st.empty()){cerr<void debug(deque st){while(!st.empty()){cerr<void debug(PQ st){while(!st.empty()){cerr<void debug(QP st){while(!st.empty()){cerr<void debug(const set&v){for(auto z:v)cerr<void debug(const multiset&v){for(auto z:v)cerr<void debug(const array &a){for(auto z:a)cerr<void debug(const map&v){for(auto z:v)cerr<<"["<void foo(Head&& head, Tail&&... tail){cerr << head << " ";foo(move(tail)...);} templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n; string s;cin >> s; vector a(n),b(n); vector> e(n); REP(i,n-1){ int u,v;cin >> u >> v; u--,v--; e[u].PB(v); e[v].PB(u); } auto dfs=[&](auto &&dfs,int cur,int pre=-1)->void{ for(auto to:e[cur]){ if(to==pre) continue; dfs(dfs,to,cur); a[cur]+=a[to],b[cur]+=b[to]; } if(s[cur]=='w'){ b[cur]+=a[cur]; a[cur]++; } }; dfs(dfs,0); // debug(a); // debug(b); ll ans=0; auto dfs2=[&](auto &&dfs2,int cur,int pre=-1,ll x=0,ll y=0)->void{ ll xx=0,yy=0; int cnt=0; // foo(cur,ans,x,y); for(auto to:e[cur]){ if(to==pre) continue; cnt++; if(s[cur]=='c') xx+=a[to]; else xx+=a[to]-1; yy+=b[to]; } xx+=x,yy+=y; if(s[cur]=='w'){ xx++; yy+=x; } // foo(xx,yy); for(auto to:e[cur]){ if(to==pre) continue; if(s[cur]=='c'){ ans+=b[to]; dfs2(dfs2,to,cur,xx-a[to],yy-b[to]); } else dfs2(dfs2,to,cur,xx-a[to]+1,yy-b[to]); } if(s[cur]=='c') ans+=y; }; dfs2(dfs2,0); cout << ans << endl; }