#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector <vector <int>> g;
vector <int> dp;
vector <bool> gen;
int ans;
void dfs (int st, int p)
{
for (auto i: g[st])
{
if (i==p) continue;
dfs(i, st);
dp[st]+=dp[i];
}
if (gen[st]) dp[st]=max(dp[st]-1, 1);
else dp[st]=max(dp[st], 0);
}
int calc (int st, int sum)
{
if (gen[st]) return max(sum-1, 1);
else return max(sum, 0);
}
void reroot (int st, int p, int dod)
{
int sum=dod;
for (auto i: g[st])
{
if (i==p) continue;
sum+=dp[i];
}
ans=max(ans, calc(st, sum));
for (auto i: g[st])
{
if (i==p) continue;
reroot(i, st, calc(st, sum-dp[i]));
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin>>n;
g.resize(n);
for (int i=0; i<n-1; i++)
{
int a, b;
cin>>a>>b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
}
string s; cin>>s;
gen.resize(n, false);
dp.resize(n);
for (int i=0; i<n; i++)
{
if (s[i]=='1') gen[i]=true;
}
dfs(0, -1);
ans=dp[0];
reroot(0, -1, 0);
int cnt=(int)count(s.begin(), s.end(), '1');
if (cnt<=2) cout<<cnt<<endl;
else cout<<max(ans, 2)<<endl;
return 0;
}