#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int N, LK, RK, LC, RC;
char A[200002];
vector<int> adj[200001];
bool bad[200001];
int sz[200001];
vector<vector<pair<int, int>>> V;
vector<pair<int, int>> all;
int bit[200006];
long long ans;
void add(int x, int v)
{
for(x++; x<=200005; x+=x&-x)
bit[x]+=v;
}
int sum(int x)
{
int ret=0;
for(x++; x>0; x-=x&-x)
ret+=bit[x];
return ret;
}
void dfs(int u, int p)
{
sz[u]=1;
for(auto& v: adj[u]) if(v!=p && !bad[v])
{
dfs(v, u);
sz[u]+=sz[v];
}
}
void dfs2(int u, int p, int K, int C)
{
if(A[u]=='K')
K++;
else
C++;
V.back().push_back(make_pair(K, C));
all.push_back(make_pair(K, C));
for(auto& v: adj[u]) if(v!=p && !bad[v])
dfs2(v, u, K, C);
}
long long work(vector<pair<int, int>>& v, int R0, int R1)
{
if(R0<0 || R1<0)
return 0;
long long ret=0;
int j=0;
for(int i=v.size()-1; i>=0; i--)
{
while(j<(int)v.size() && v[i].first+v[j].first<=R0)
{
add(v[j].second, 1);
j++;
}
ret+=sum(R1-v[i].second);
if(j>=i && v[i].first*2<=R0 && v[i].second*2<=R1)
ret--;
}
for(int i=0; i<j; i++)
add(v[i].second, -1);
return ret/2;
}
long long work(vector<pair<int, int>>& v)
{
sort(v.begin(), v.end());
return work(v, RK, RC)-work(v, LK-1, RC)-work(v, RK, LC-1)+work(v, LK-1, LC-1);
}
void solve(int u)
{
dfs(u, -1);
while(1)
{
int idx=-1;
for(auto& v: adj[u]) if(!bad[v] && (idx==-1 || sz[v]>sz[idx]))
idx=v;
if(sz[idx]*2<=sz[u])
break;
sz[u]-=sz[idx];
sz[idx]+=sz[u];
u=idx;
}
if((A[u]=='K' && LK<=1 && LC==0) || (A[u]=='C' && LC<=1 && LK==0))
ans++;
if((A[u]=='K' && RK==0) || (A[u]=='C' && RC==0))
goto skip;
if(A[u]=='K')
LK--, RK--;
else
LC--, RC--;
V.clear();
all.clear();
for(auto& v: adj[u]) if(!bad[v])
{
V.push_back(vector<pair<int, int>>());
dfs2(v, u, 0, 0);
for(auto& it: V.back())
if(LK<=it.first && it.first<=RK && LC<=it.second && it.second<=RC)
ans++;
}
ans+=work(all);
for(auto& it: V)
ans-=work(it);
if(A[u]=='K')
LK++, RK++;
else
LC++, RC++;
skip:;
bad[u]=true;
for(auto& v: adj[u]) if(!bad[v])
solve(v);
}
int dfs_bf(int u, int p, int K, int C)
{
if(A[u]=='K')
K++;
else
C++;
int ret=0;
if(LK<=K && K<=RK && LC<=C && C<=RC)
ret++;
for(auto& v: adj[u]) if(v!=p)
ret+=dfs_bf(v, u, K, C);
return ret;
}
long long solve_bf()
{
long long ret=0;
for(int i=1; i<=N; i++)
{
ret+=dfs_bf(i, -1, 0, 0);
if(LK<=(A[i]=='K') && (A[i]=='K')<=RK && LC<=(A[i]=='C') && (A[i]=='C')<=RC)
ret++;
}
return ret/2;
}
int main()
{
scanf("%d%d%d%d%d", &N, &LK, &RK, &LC, &RC);
scanf("%s", A+1);
int a, b;
for(int i=1; i<N; i++)
{
scanf("%d%d", &a, &b);
adj[a].push_back(b);
adj[b].push_back(a);
}
solve(1);
printf("%lld\n", ans);
//printf("%lld\n", solve_bf());
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBOLCBMSywgUkssIExDLCBSQzsKY2hhciBBWzIwMDAwMl07CnZlY3RvcjxpbnQ+IGFkalsyMDAwMDFdOwpib29sIGJhZFsyMDAwMDFdOwppbnQgc3pbMjAwMDAxXTsKdmVjdG9yPHZlY3RvcjxwYWlyPGludCwgaW50Pj4+IFY7CnZlY3RvcjxwYWlyPGludCwgaW50Pj4gYWxsOwppbnQgYml0WzIwMDAwNl07CmxvbmcgbG9uZyBhbnM7Cgp2b2lkIGFkZChpbnQgeCwgaW50IHYpCnsKICAgIGZvcih4Kys7IHg8PTIwMDAwNTsgeCs9eCYteCkKICAgICAgICBiaXRbeF0rPXY7Cn0KCmludCBzdW0oaW50IHgpCnsKICAgIGludCByZXQ9MDsKICAgIGZvcih4Kys7IHg+MDsgeC09eCYteCkKICAgICAgICByZXQrPWJpdFt4XTsKICAgIHJldHVybiByZXQ7Cn0KCnZvaWQgZGZzKGludCB1LCBpbnQgcCkKewogICAgc3pbdV09MTsKICAgIGZvcihhdXRvJiB2OiBhZGpbdV0pIGlmKHYhPXAgJiYgIWJhZFt2XSkKICAgIHsKICAgICAgICBkZnModiwgdSk7CiAgICAgICAgc3pbdV0rPXN6W3ZdOwogICAgfQp9Cgp2b2lkIGRmczIoaW50IHUsIGludCBwLCBpbnQgSywgaW50IEMpCnsKICAgIGlmKEFbdV09PSdLJykKICAgICAgICBLKys7CiAgICBlbHNlCiAgICAgICAgQysrOwogICAgVi5iYWNrKCkucHVzaF9iYWNrKG1ha2VfcGFpcihLLCBDKSk7CiAgICBhbGwucHVzaF9iYWNrKG1ha2VfcGFpcihLLCBDKSk7CiAgICBmb3IoYXV0byYgdjogYWRqW3VdKSBpZih2IT1wICYmICFiYWRbdl0pCiAgICAgICAgZGZzMih2LCB1LCBLLCBDKTsKfQoKbG9uZyBsb25nIHdvcmsodmVjdG9yPHBhaXI8aW50LCBpbnQ+PiYgdiwgaW50IFIwLCBpbnQgUjEpCnsKICAgIGlmKFIwPDAgfHwgUjE8MCkKICAgICAgICByZXR1cm4gMDsKICAgIGxvbmcgbG9uZyByZXQ9MDsKICAgIGludCBqPTA7CiAgICBmb3IoaW50IGk9di5zaXplKCktMTsgaT49MDsgaS0tKQogICAgewogICAgICAgIHdoaWxlKGo8KGludCl2LnNpemUoKSAmJiB2W2ldLmZpcnN0K3Zbal0uZmlyc3Q8PVIwKQogICAgICAgIHsKICAgICAgICAgICAgYWRkKHZbal0uc2Vjb25kLCAxKTsKICAgICAgICAgICAgaisrOwogICAgICAgIH0KICAgICAgICByZXQrPXN1bShSMS12W2ldLnNlY29uZCk7CiAgICAgICAgaWYoaj49aSAmJiB2W2ldLmZpcnN0KjI8PVIwICYmIHZbaV0uc2Vjb25kKjI8PVIxKQogICAgICAgICAgICByZXQtLTsKICAgIH0KICAgIGZvcihpbnQgaT0wOyBpPGo7IGkrKykKICAgICAgICBhZGQodltpXS5zZWNvbmQsIC0xKTsKICAgIHJldHVybiByZXQvMjsKfQoKbG9uZyBsb25nIHdvcmsodmVjdG9yPHBhaXI8aW50LCBpbnQ+PiYgdikKewogICAgc29ydCh2LmJlZ2luKCksIHYuZW5kKCkpOwogICAgcmV0dXJuIHdvcmsodiwgUkssIFJDKS13b3JrKHYsIExLLTEsIFJDKS13b3JrKHYsIFJLLCBMQy0xKSt3b3JrKHYsIExLLTEsIExDLTEpOwp9Cgp2b2lkIHNvbHZlKGludCB1KQp7CiAgICBkZnModSwgLTEpOwogICAgd2hpbGUoMSkKICAgIHsKICAgICAgICBpbnQgaWR4PS0xOwogICAgICAgIGZvcihhdXRvJiB2OiBhZGpbdV0pIGlmKCFiYWRbdl0gJiYgKGlkeD09LTEgfHwgc3pbdl0+c3pbaWR4XSkpCiAgICAgICAgICAgIGlkeD12OwogICAgICAgIGlmKHN6W2lkeF0qMjw9c3pbdV0pCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIHN6W3VdLT1zeltpZHhdOwogICAgICAgIHN6W2lkeF0rPXN6W3VdOwogICAgICAgIHU9aWR4OwogICAgfQogICAgaWYoKEFbdV09PSdLJyAmJiBMSzw9MSAmJiBMQz09MCkgfHwgKEFbdV09PSdDJyAmJiBMQzw9MSAmJiBMSz09MCkpCiAgICAgICAgYW5zKys7CiAgICBpZigoQVt1XT09J0snICYmIFJLPT0wKSB8fCAoQVt1XT09J0MnICYmIFJDPT0wKSkKICAgICAgICBnb3RvIHNraXA7CiAgICBpZihBW3VdPT0nSycpCiAgICAgICAgTEstLSwgUkstLTsKICAgIGVsc2UKICAgICAgICBMQy0tLCBSQy0tOwogICAgVi5jbGVhcigpOwogICAgYWxsLmNsZWFyKCk7CiAgICBmb3IoYXV0byYgdjogYWRqW3VdKSBpZighYmFkW3ZdKQogICAgewogICAgICAgIFYucHVzaF9iYWNrKHZlY3RvcjxwYWlyPGludCwgaW50Pj4oKSk7CiAgICAgICAgZGZzMih2LCB1LCAwLCAwKTsKICAgICAgICBmb3IoYXV0byYgaXQ6IFYuYmFjaygpKQogICAgICAgICAgICBpZihMSzw9aXQuZmlyc3QgJiYgaXQuZmlyc3Q8PVJLICYmIExDPD1pdC5zZWNvbmQgJiYgaXQuc2Vjb25kPD1SQykKICAgICAgICAgICAgICAgIGFucysrOwogICAgfQogICAgYW5zKz13b3JrKGFsbCk7CiAgICBmb3IoYXV0byYgaXQ6IFYpCiAgICAgICAgYW5zLT13b3JrKGl0KTsKICAgIGlmKEFbdV09PSdLJykKICAgICAgICBMSysrLCBSSysrOwogICAgZWxzZQogICAgICAgIExDKyssIFJDKys7CiAgICBza2lwOjsKICAgIGJhZFt1XT10cnVlOwogICAgZm9yKGF1dG8mIHY6IGFkalt1XSkgaWYoIWJhZFt2XSkKICAgICAgICBzb2x2ZSh2KTsKfQoKaW50IGRmc19iZihpbnQgdSwgaW50IHAsIGludCBLLCBpbnQgQykKewogICAgaWYoQVt1XT09J0snKQogICAgICAgIEsrKzsKICAgIGVsc2UKICAgICAgICBDKys7CiAgICBpbnQgcmV0PTA7CiAgICBpZihMSzw9SyAmJiBLPD1SSyAmJiBMQzw9QyAmJiBDPD1SQykKICAgICAgICByZXQrKzsKICAgIGZvcihhdXRvJiB2OiBhZGpbdV0pIGlmKHYhPXApCiAgICAgICAgcmV0Kz1kZnNfYmYodiwgdSwgSywgQyk7CiAgICByZXR1cm4gcmV0Owp9Cgpsb25nIGxvbmcgc29sdmVfYmYoKQp7CiAgICBsb25nIGxvbmcgcmV0PTA7CiAgICBmb3IoaW50IGk9MTsgaTw9TjsgaSsrKQogICAgewogICAgICAgIHJldCs9ZGZzX2JmKGksIC0xLCAwLCAwKTsKICAgICAgICBpZihMSzw9KEFbaV09PSdLJykgJiYgKEFbaV09PSdLJyk8PVJLICYmIExDPD0oQVtpXT09J0MnKSAmJiAoQVtpXT09J0MnKTw9UkMpCiAgICAgICAgICAgIHJldCsrOwogICAgfQogICAgcmV0dXJuIHJldC8yOwp9CgppbnQgbWFpbigpCnsKICAgIHNjYW5mKCIlZCVkJWQlZCVkIiwgJk4sICZMSywgJlJLLCAmTEMsICZSQyk7CiAgICBzY2FuZigiJXMiLCBBKzEpOwogICAgaW50IGEsIGI7CiAgICBmb3IoaW50IGk9MTsgaTxOOyBpKyspCiAgICB7CiAgICAgICAgc2NhbmYoIiVkJWQiLCAmYSwgJmIpOwogICAgICAgIGFkalthXS5wdXNoX2JhY2soYik7CiAgICAgICAgYWRqW2JdLnB1c2hfYmFjayhhKTsKICAgIH0KICAgIHNvbHZlKDEpOwogICAgcHJpbnRmKCIlbGxkXG4iLCBhbnMpOwogICAgLy9wcmludGYoIiVsbGRcbiIsIHNvbHZlX2JmKCkpOwogICAgcmV0dXJuIDA7Cn0K