#include #define int long long using namespace std; void file_IO(){ freopen("cww.in", "r", stdin); freopen("cww.out", "w", stdout); } const int N = 1e5 + 10; int n, cnt = 0, ans = 0, ch[N], sz[N][2]; vector g[N]; void dfs(int u, int fno){ sz[u][ch[u] ^ 1] = 0, sz[u][ch[u]] = 1; for (auto v : g[u]) if (v ^ fno){ dfs(v, u); for (int x : {0, 1}) sz[u][x] += sz[v][x]; if (ch[u]) ans += sz[v][0] * (cnt - 1 - sz[v][1]); } if (ch[u]) ans += (n - cnt - sz[u][0]) * (sz[u][1] - 1); } signed main(){ //file_IO(); ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++){ char x; cin >> x; ch[i] = (x == 'w' ? 1 : 0), cnt += ch[i]; } for (int i = 1, u, v; i < n; i++){ cin >> u >> v; g[u].push_back(v), g[v].push_back(u); } dfs(1, 0); cout << ans << endl; return 0; }