#include using namespace std; typedef long long ll; typedef vector< int > vi; typedef vector< vi > vvi; typedef vector< ll > vl; typedef vector< vl > vvl; typedef pair< int, int > pii; typedef vector< pii > vp; typedef vector< double > vd; typedef vector< vd > vvd; typedef vector< string > vs; template< class T1, class T2 > int upmin( T1 &x, T2 v ){ if( x > v ){ x = v; return 1; } return 0; } template< class T1, class T2 > int upmax( T1 &x, T2 v ){ if( x < v ){ x = v; return 1; } return 0; } const int INF = 0x3f3f3f3f; int N; string seq; vvi G; void init(){ cin >> N; cin >> seq; G = vvi( N ); for( int i = 0; i < N - 1; ++i ){ int u, v; cin >> u >> v; G[ u - 1 ].emplace_back( v - 1 ); G[ v - 1 ].emplace_back( u - 1 ); } } const int MAXN = ( int ) 1e5; ll dp_d[ MAXN + 1 ][ 2 ]; // how many "ww"s / how many "w"s ll dp_u[ MAXN + 1 ][ 2 ]; void dfs_d( int u, int fa ){ ll ww = 0, w = 0; for( int v : G[ u ] ){ if( v == fa ) continue; dfs_d( v, u ); ww += dp_d[ v ][ 0 ]; w += dp_d[ v ][ 1 ]; } if( seq[ u ] == 'w' ){ ww += w; ++w; } dp_d[ u ][ 0 ] = ww; dp_d[ u ][ 1 ] = w; } void dfs_u( int u, int fa, ll upww, ll upw ){ dp_u[ u ][ 0 ] = upww; dp_u[ u ][ 1 ] = upw; for( int v : G[ u ] ){ if( v == fa ) continue; upww += dp_d[ v ][ 0 ]; upw += dp_d[ v ][ 1 ]; } for( int v : G[ u ] ){ if( v == fa ) continue; ll nupww = upww - dp_d[ v ][ 0 ]; ll nupw = upw - dp_d[ v ][ 1 ]; if( seq[ u ] == 'w' ){ nupww += nupw; ++nupw; } dfs_u( v, u, nupww, nupw ); } } void preprocess(){ dfs_d( 0, -1 ); dfs_u( 0, -1, 0, 0 ); } void solve(){ ll ans = 0; for( int i = 0; i < N; ++i ){ if( seq[ i ] == 'c' ){ ans += dp_d[ i ][ 0 ] + dp_u[ i ][ 0 ]; } } cout << ans << endl; } signed main(){ ios::sync_with_stdio( 0 ); init(); preprocess(); solve(); return 0; }