#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define Add(x, y) (x + y >= mod) ? (x + y - mod) : (x + y)
#define lowbit(x) x & (-x)
#define pi pair<ll, ll>
#define pii pair<ll, pair<ll, ll>>
#define iip pair<pair<ll, ll>, ll>
#define ppii pair<pair<ll, ll>, pair<ll, ll>>
#define ls(k) k << 1
#define rs(k) k << 1 | 1
#define fi first
#define se second
#define full(l, r, x) for(auto it = l; it != r; ++it) (*it) = x
#define Full(a) memset(a, 0, sizeof(a))
#define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
#define For(i, l, r) for(register int i = l; i <= r; ++i)
#define _For(i, l, r) for(register int i = r; i >= l; --i)
using namespace std;
using namespace __gnu_pbds;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
bool Begin;
const int N = 1e5 + 10;
inline ll read(){
    ll x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-')
          f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return x * f;
}
inline void write(ll x){
	if(x < 0){
		putchar('-');
		x = -x;
	}
	if(x > 9)
	  write(x / 10);
	putchar(x % 10 + '0');
}
ll ans;
int n, as1, as2;
int s1[N], s2[N], fa[N];
char s[N];
vector<int> E[N];
inline void add(int u, int v){
	E[u].push_back(v);
	E[v].push_back(u);
}
inline void dfs1(int u, int f){
	s1[u] = (s[u] == 'c'), s2[u] = s1[u] ^ 1;
	for(auto v : E[u]){
		if(v == f)
		  continue;
		fa[v] = u;
		dfs1(v, u);
		s1[u] += s1[v], s2[u] += s2[v];
	}
}
bool End;
int main(){
	n = read();
	scanf("%s", s + 1);
	for(int u, v, i = 1; i < n; ++i){
		u = read(), v = read();
		add(u, v);
	}
	for(int i = 1; i <= n; ++i){
		as1 += (s[i] == 'c');
		as2 += (s[i] == 'w');
	}
	dfs1(1, 1);
	for(int i = 1; i <= n; ++i){
		if(s[i] == 'c')
		  continue;
		int ns1 = s1[i], ns2 = s2[i] - 1;
		int ps1 = as1 - s1[i], ps2 = as2 - s2[i];
		ans += 1ll * ns1 * ps2 + 1ll * ns2 * ps1;
		int son = E[i].size();
		for(int x = 0; x < son; ++x){
			if(E[i][x] == fa[i])
			  continue;
			for(int y = x + 1; y < son; ++y){
				if(E[i][y] == fa[i])
				  continue;
				ans += 1ll * s1[E[i][x]] * s2[E[i][y]] + 1ll * s2[E[i][x]] * s1[E[i][y]];
			}
		}
	}
	write(ans);
	cerr << '\n' << abs(&Begin - &End) / 1048576 << "MB";
	return 0;
}