#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long int #define ti4 tuple #define pii pair #define REP(x,n) for(int x = 0;x < n;x++) struct UnionFind { vector data; UnionFind(ll size) : data(size, -1) { } bool unionSet(ll x, ll y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(ll x, ll y) { return root(x) == root(y); } ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(ll x) { return -data[root(x)]; } }; bool cw[1000001]; vector v[1000001]; int main() { int n; cin >> n; string ss; cin >> ss; for(int i = 0;i < n;i++) { if(ss[i] == 'c') { cw[i] = true; } else { cw[i] = false; } } vector start; for(int i = 0;i < n-1;i++) { int a,b; cin >> a >> b; a--; b--; bool f = cw[a]; bool t = cw[b]; if(f) { start.push_back(a); if(!t) { v[a].push_back(b); } } else if(t) { start.push_back(b); v[b].push_back(a); } else { v[a].push_back(b); v[b].push_back(a); } } ll sum = 0; for(auto e : start) { const vector& second = v[e]; for(auto t : second) { sum += v[t].size(); } } cout << sum << endl; return 0; }