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

typedef long long ll;

const int MN = 200010;

int N;
vector<int> adj[MN];
char S[MN];
int dist[MN], par[MN], x;
ll ans;

void dfs0(int u, int p) {
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        dist[v] = dist[u] + 1;
        par[v] = u;
        dfs0(v, u);
    }
}

int dp[MN];

int dfs1(int u, int p) {
    int ret = 0;
    int mn = 1e9;
    dp[u] = S[u] == '1'? 1 : 0;
    if(dp[u]) mn = 0;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        int t = dfs1(v, u);
        ret = max(ret, t + 1);
        if(dp[v]) mn = min(mn, t + 1);
        dp[u] |= dp[v];
    }
    if(dp[u]) {
        //cout << u << ' ' << ret << ' ' << dist[x] << ' ' << ret << ' ' << mn << endl;

        if(ret >= dist[x] / 2) ans += ret + 1 - mn;
        else ans += ret + 2 - mn;
    }
    return ret;
}

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N - 1; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    scanf("\n");
    for(int i = 0; i < N; i++) {
        scanf("%c", &S[i]);
    }

    dfs0(0, -1);
    int p = 0;
    for(int i = 0; i < N; i++) if(dist[p] < dist[i]) p = i;
    dist[p] = 0;
    dfs0(p, -1);
    for(int i = 0; i < N; i++) if(dist[x] < dist[i]) x = i;

    int root = x;
    while(dist[root] > dist[x] / 2) {
        root = par[root];
    }
    dfs1(root, -1);
    printf("%lld", ans);
}
