// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 2e5;

int n;

vector<int> adj[MAXN + 5];

int type[MAXN + 5];

inline char safe_getchar()
{
	register char ch(getchar());
	while(!isdigit(ch)) ch = getchar();
	return ch;
}

inline void input()
{
	n = read<int>();
	for(int i = 1; i < n; ++i)
	{
		int u = read<int>(), v = read<int>();
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i = 1; i <= n; ++i) type[i] = safe_getchar() - '0';
}

const int INF = (int) 1e9;

int f[MAXN + 5], g[MAXN + 5], anc[MAXN + 5];

inline void dfs_f(int u, int fa)
{
	anc[u] = fa;

	f[u] = 0;
	for(auto v : adj[u]) if(v != fa)
	{
		dfs_f(v, u);
		chkmax(f[u], f[v] + 1);
	}
}

inline void dfs_g(int u, int fa)
{
	int deg = SZ(adj[u]) - 1;

	static int pre[MAXN + 5], suf[MAXN + 5];

	for(int i = 0; i <= deg; ++i)
	{
		int v = adj[u][i];
		pre[i] = suf[i] = v == fa ? 0 : f[v] + 1;
	}
	for(int i = 1; i <= deg; ++i) chkmax(pre[i], pre[i - 1]);
	for(int i = deg - 1; i >= 0; --i) chkmax(suf[i], suf[i + 1]);

	for(int i = 0; i <= deg; ++i)
	{
		int v = adj[u][i];
		if(v != fa)
		{
			int res = g[u];
			if(i > 0) chkmax(res, pre[i - 1]);
			if(i < deg) chkmax(res, suf[i + 1]);
			chkmax(g[v], res + 1);
		}
	}

	for(auto v : adj[u]) if(v != fa)
		dfs_g(v, u);
}

int size[MAXN + 5], p[MAXN + 5], q[MAXN + 5];

inline void dfs_pq(int u, int fa, int tot)
{
	p[u] = type[u] ? 0 : INF;

	size[u] = type[u];
	for(auto v : adj[u]) if(v != fa)
	{
		dfs_pq(v, u, tot);
		if(size[v]) chkmin(p[u], f[v] + 1);
		size[u] += size[v];
	}

	q[u] = size[u] == tot ? INF : g[u];
}

inline void solve()
{
	dfs_f(1, 0);
	dfs_g(1, 0);

	int tot = 0;
	for(int i = 1; i <= n; ++i) tot += type[i];
	dfs_pq(1, 0, tot);

	LL ans = 1;
	for(int u = 1; u <= n; ++u)
	{
		int l = type[u] ? 0 : min(p[u], q[u]), r = max(f[u], g[u]) - 1;
		for(auto v : adj[u])
		{
			if(v == anc[u]) chkmin(r, f[u] + 1);
			else chkmin(r, g[v]);
		}
		ans += max(0, r - l + 1);
	}
	printf("%lld\n", ans);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}

