#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define bit(n) (1LL<<(n)) #define sz(x) ((int)(x).size()) #define fst first #define snd second using ll=long long;using pii=pair;using vb=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; template T read() {T t; cin >> t; return t;} void Main() { int n = read(); auto s = read(); vvi E(n); rep(i, n-1) { int u = read() - 1; int v = read() - 1; E[u].push_back(v); E[v].push_back(u); } vi ww(n), w(n); function dfs1 = [&](int cur, int pre) { forr(nex, E[cur]) if (nex != pre) { dfs1(nex, cur); w[cur] += w[nex]; ww[cur] += ww[nex]; } if (s[cur] == 'w') { ww[cur] += w[cur]; w[cur]++; } }; ll ans = 0; function dfs2 = [&](int cur, int pre, int nww, int nw) { //_p("dfs2(%d,%d,%d,%d)\n",cur,pre,nww,nw); if (s[cur] == 'c') { ans += ww[cur]; ans += nww; } forr(nex, E[cur]) if (nex != pre) { int nex_nw, nex_nww; if (s[cur] == 'w') { nex_nww = nww + nw + (w[cur] - w[nex] - 1); nex_nw = nw + (w[cur] - w[nex]); } else { nex_nww = nww + (ww[cur] - ww[nex]); nex_nw = nw + (w[cur] - w[nex]); } dfs2(nex, cur, nex_nww, nex_nw); } }; rep(i, n) if (s[i] == 'c') { dfs1(i, -1); //cout<<"i: "<