#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<set<int>> graph(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        graph[u].insert(v);
        graph[v].insert(u);
    }
    vector<int> c(n);
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'B') {
            c[i] = 1;
        } else { 
            c[i] = 0;
        }
    }
    if (n == 1) {
        if (c[0]) {
            cout << 0 << '\n';
        } else {
            cout << 1 << '\n';
        }
        return 0;
    }
    set<int> good;
    set<int> black_leaves;
    for (int i = 0; i < n; i++) {
        if (c[i] && (int) graph[i].size() == 1) {
            black_leaves.insert(i);
        }
        good.insert(i);
    }
    while ((int) black_leaves.size()) {
        int x = *black_leaves.begin();
        good.erase(x);
        black_leaves.erase(x);
        for (int nxt: graph[x]) {
            graph[nxt].erase(x);
        }
        for (int nxt: graph[x]) {
            if ((int) graph[nxt].size() == 1 && c[nxt]) {
                black_leaves.insert(nxt);
            }
        }
        graph[x].clear();
    }
    map<int, int> conv;
    int cnt = 0;
    vector<int> col(n);
    for (int x: good) {
        conv[x] = cnt;
        col[cnt] = c[x];
        cnt++;
    }
    vector<vector<int>> adj(cnt);
    for (int i = 0; i < n; i++) {
        if (good.count(i)) {
            for (int j: graph[i]) {
                adj[conv[i]].push_back(conv[j]);
            }
        }
    }
    n = cnt;
    if (n == 0) {
        cout << 0 << '\n';
        return 0;
    }
    int tot = 2 * (n - 1);
    vector<int> sz(n);
    vector<int> val(n);
    for (int i = 0; i < n; i++) {
        sz[i] = (int) adj[i].size();
    }
    tot++; 
    for (int i = 0; i < n; i++) {
        if (sz[i] == 1) {
            val[i] = -1;
            continue;
        }
        if (col[i]) {
            tot += (sz[i] % 2 == 1);
            val[i] = (sz[i] % 2 == 0) - (sz[i] % 2 == 1) - 1;
        } else {
            tot += (sz[i] % 2 == 0);
            val[i] = (sz[i] % 2 == 1) - (sz[i] % 2 == 0) - 1;
        }
    }
    int add = 1e9;
    function<int(int, int)> dfs = [&](int src, int par) -> int {
        multiset<int> chains;
        for (int nxt: adj[src]) {
            if (nxt == par) continue;
            chains.insert(dfs(nxt, src));
        }
        int ret = *chains.begin() + val[src];
        add = min(add, ret);
        if ((int) chains.size() >= 2) {
            add = min(add, *chains.begin() + *next(chains.begin()) + val[src]);
        }
        return ret;
    };
    dfs(0, -1);
    int ans = tot + add + 1;
    cout << ans << '\n';
}

Measured memory_bytes: 49116