#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cstdio>
#include <deque>
using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
vector<vector<int> > v;
vector<int>c;
vector<int>d;
vector<bool>del;

int main(){
    int n;
    cin >> n;
    v.resize(n);
    rep(i,n-1){
        int x,y;
        cin >> x >> y;
        x--;y--;
        v[x].PB(y);
        v[y].PB(x);
    }
    string S;
    cin >> S;
    c.resize(n);
    rep(i,n)if(S[i]=='B')c[i] = 1;
    d.resize(n);
    del.resize(n);
    rep(i,n){
        d[i] = v[i].size();
    }
    queue<int>q;
    rep(i,n){
        if(d[i]<=1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int x = q.front();
        q.pop();
        if(c[x]==1){
            del[x] = 1;
            for(auto y:v[x]){
                d[y]--;
                if(d[y]==1){
                    q.push(y);
                }
            }
        }
    }
    int cnt = 0;
    rep(i,n){
        if(!del[i]){
            cnt++;
        }
    }
    if(cnt==0){
        cout << 0 << endl;
        return 0;
    }else if(cnt==1){
        cout << 1 << endl;
        return 0;
    }
    int ans = 0;
    vector<int> z(n);
    int st=-1;
    rep(i,n){
        if(!del[i]){
            if(st==-1)st = i;
            if(d[i]==1){
                ans++;
            }else{
                if(d[i]%2==0){
                    if(c[i]==0){
                        ans +=d[i]+1;
                        z[i] = 1;
                    }else{
                        ans +=d[i];
                    }
                }else{
                    if(c[i]==0){
                        ans +=d[i];
                    }else{
                        ans +=d[i]+1;
                        z[i] = 1;
                    }
                }
            }
        }
    }
    vector<bool> used(n),used2(n);
    deque<int>dq;
    dq.push_front(st);
    used[st] = 1;
    int ed;
   while(!dq.empty()){
        int pp = dq.front();
        ed = pp;
        dq.pop_front();
        for(auto x:v[pp]){
            if(used[x]==0&&del[x]==0){
                used[x]=1;
                if(z[x]==0){
                    dq.push_front(x);
                }else{
                    dq.push_back(x);
                }
            }
        }
    }
    deque<pair<int,int> > dq2;
    dq2.push_back(MP(ed,0));
    int mmm;
    used2[ed]=1;
    while(!dq2.empty()){
        auto pp = dq2.front();
        mmm = pp.second;
        dq2.pop_front();
        for(auto x:v[pp.first]){
            if(used2[x]==0&&del[x]==0){
                used2[x]=1;
                if(z[x]==0){
                    dq2.push_front(MP(x,pp.second));
                }else{
                    dq2.push_back(MP(x,pp.second+1));
                }
            }
        }
    }
    cout << ans -2*mmm << endl;
    return 0;
}

Measured memory_bytes: 8312