果然要自己写一遍!!!
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
using ll=long long;
//HDU 7339
const ll qz[]={998244353,1000000007,-998244353-1000000007};
ll n,a[(int)1e5+9],sz[(int)1e5+9],son[(int)1e5+9],dfn[(int)1e5+9],revdfn[(int)1e5+9],dfncnt,ans;
ll val[(int)1e5+9];
vector<int> g[(int)1e5+9];
void dfs(int u,int fa){
val[u]=val[fa]+a[u];
sz[u]=1,dfn[u]=++dfncnt,revdfn[dfncnt]=u;
for(auto it:g[u])if(it!=fa){
dfs(it,u);
son[u]=sz[it]>sz[son[u]]?it:son[u],sz[u]+=sz[it];
}
}
map<ll,int> cn;
void dsu(int u,int fa){
for(auto it:g[u])if(it!=fa&&it!=son[u]){
dsu(it,u);
cn.clear();
}
if(son[u])dsu(son[u],u);
auto cal=[&](int now,int lca,int lcafa){
ll need=val[now]-val[lca]-val[lcafa];
return cn[-need];
};
for(auto it:g[u])if(it!=fa&&it!=son[u]){
for(int i=dfn[it];i<dfn[it]+sz[it];++i){
ans+=cal(revdfn[i],u,fa);
}
for(int i=dfn[it];i<dfn[it]+sz[it];++i)cn[val[revdfn[i]]]+=1;
}
ans+=cal(u,u,fa);
cn[val[u]]+=1;
}
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;++i){
char c;
scanf(" %c",&c);
a[i]=qz[c-'a'];
}
for(int i=1,x,y;i<n;++i){
scanf("%d%d",&x,&y);
g[x].push_back(y),g[y].push_back(x);
}
dfs(1,0);
dsu(1,0);
printf("%lld\n", ans);
return 0;
}