#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

void dfs1(int n, int p, int d, vector<int> &dis, vector<vector<int>> &graph) {
	dis[n] = d;
	for (int i : graph[n]) {
		if (i == p) continue;
		dfs1(i, n, d + 1, dis, graph);
	}
}

void dfs2(int n, int p, vector<vector<int>> &graph, vector<ll> &cnt) {
	int res = 1;
	for (int i : graph[n]) {
		if (i == p) continue;
		dfs2(i, n, graph, cnt);
		chmax(res, cnt[i] + 1);
	}
	cnt[n] = res;
}


void dfs3(int n, int p, vector<int> &d, int rad, vector<vector<int>> &graph, vector<ll> &ma) {
	ma[n] = rad - d[n] + 1;
	for (int i : graph[n]) {
		if (i == p) continue;
		dfs3(i, n, d, rad, graph, ma);
		chmin(ma[n], ma[i]);
	}
}

void dfs4(int n, int p, string &s, vector<vector<int>> &graph, vector<ll> &ma, vector<ll> &val, vector<bool> &ok) {
	int res = 0;
	if (s[n] == '1') ok[n] = true;
	for (int i : graph[n]) {
		if (i == p) continue;
		dfs4(i, n, s, graph, ma, val, ok);
		if (ok[i]) {
			ok[n] = true;
			chmax(res, ma[i]);
		}
	}
	if (ok[n]) val[n] = res;
}

ll solve(int n, vector<vector<int>> &graph, string &s) {
	vector<ll> cnt(200010);
	vector<ll> ma(200010), val(200010);
	ll ans = 0;
	vector<int> xd(n), yd(n);
	dfs1(0, -1, 0, xd, graph);
	int ver = -1; int tmp = 0;
	rep(i, n) if (chmax(tmp, xd[i])) ver = i;
	dfs1(ver, -1, 0, xd, graph);
	int rver = -1; tmp = 0;
	rep(i, n) if (chmax(tmp, xd[i])) rver = i;
	dfs1(rver, -1, 0, yd, graph);
	int diam = xd[rver];
	if (diam & 1) {
		int cen, cen2;
		rep(i, n) {
			if (xd[i] == diam / 2 && yd[i] == diam / 2 + 1) cen = i;
			if (xd[i] == diam / 2 + 1 && yd[i] == diam / 2) cen2 = i;
		}
		dfs2(cen, cen2, graph, cnt); dfs2(cen2, cen, graph, cnt);
		vector<int> dis(n); vector<bool> ok(n);
		dfs1(cen, cen2, 0, dis, graph); dfs3(cen, cen2, dis, diam / 2, graph, ma); dfs4(cen, cen2, s, graph, ma, val, ok);
		dfs1(cen2, cen, 0, dis, graph); dfs3(cen2, cen, dis, diam / 2, graph, ma); dfs4(cen2, cen, s, graph, ma, val, ok);
		rep(i, n) {
			if (i != cen && i != cen2 && s[i] == '1') ans += cnt[i] + 1;
			if (s[i] == '0' && val[i]) {
				if (i == cen || i == cen2) ans += val[i];
				else ans += val[i] - diam / 2 + dis[i] + cnt[i];
			}
		}
		if (s[cen] == '1') ans += cnt[cen];
		if (s[cen2] == '1') ans += cnt[cen2];
		ans++;
	}
	else {
		int cen;
		rep(i, n) {
			if (xd[i] == diam / 2 && yd[i] == diam / 2) cen = i;
		}
		dfs2(cen, -1, graph, cnt);
		vector<int> dis(n); vector<bool> ok(n);
		dfs1(cen, -1, 0, dis, graph); dfs3(cen, -1, dis, diam / 2, graph, ma); dfs4(cen, -1, s, graph, ma, val, ok);
		rep(i, n) {
			if (i != cen && s[i] == '1') ans += cnt[i] + 1;
			else if (s[i] == '0' && val[i]) {
				if (i == cen) ans += val[i] - 1;
				else ans += val[i] - diam / 2 + dis[i] + cnt[i];
			}
		}
		if (s[cen] == '1') ans += cnt[cen];
		else ans++;
	}
	return ans;
}

ll solve2(int n, vector<vector<int>> &graph, string &s) {
	set<vector<int>> st;
	rep(i, n) {
		rep(j, n) {
			if (s[i] == '0') continue;
			vector<int> vec(n);
			queue<P> q;
			q.push({ i,0 }); vec[i] = 1;
			while (!q.empty()) {
				P p = q.front(); q.pop();
				int v = p.first; int d = p.second;
				if (d == j) continue;
				for (int nxt : graph[v]) {
					if (!vec[nxt]) {
						vec[nxt] = 1;
						q.push({ nxt,d + 1 });
					}
				}
			}
			st.insert(vec);
		}
	}
	return st.size();
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<vector<int>> graph(n, vector<int>());
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph[u].pb(v);
		graph[v].pb(u);
	}
	string s;
	cin >> s;
	cout << solve(n, graph, s) << '\n';
	/*rep(i, (1 << n)) {
		if (i == 0) continue;
		string s = "";
		rep(j, n) {
			if ((i >> j) & 1) s += '1';
			else s += '0';
		}
		if (solve(n, graph, s) != solve2(n, graph, s)) {
			debug(s);
			debug(solve(n, graph, s));
			debug(solve2(n, graph, s));
		}
	}*/
}

Measured memory_bytes: 36928