#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back(a) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<(x)< > vec; vector label; vector memoc, memow; int sumc, sumw; long dfs(int from, int d){ long tmpc=0, tmpw=0, ret=0; for(auto i : vec[d]) if(i != from){ ret += dfs(d, i); tmpc += memoc[i]; tmpw += memow[i]; } memoc[d] = tmpc + (label[d]=='c'); memow[d] = tmpw + (label[d]=='w'); if(label[d]=='w'){ for(auto i : vec[d]) if(i != from){ ret += memoc[i] * (sumw-memow[i]-1); ret += memow[i] * (sumc-memoc[i]); } } return ret; } int main(){ int n; scanf("%d\n", &n); vec = vector >(n,vector()); label = vector(n); rep(i,n) scanf("%c", &label[i]); rep(i,n-1){ int a,b; scanf("%d %d", &a, &b); a--; b--; vec[a].pb(b); vec[b].pb(a); } sumc=0; sumw=0; rep(i,n){ if(label[i]=='c') sumc++; else sumw++; } memoc = vector(n, 0); memow = vector(n, 0); cout<