#include <bits/stdc++.h>
using namespace std;
#define MAXN 200005
int n;string state;
vector<int> adj[MAXN];
int dp[MAXN];int answer=0;
int parent[MAXN];int suma[MAXN];
void dfs(int node,int pret)
{
int children=0;parent[node]=pret;
for (int sled:adj[node])
{
if (sled==pret) continue;
dfs(sled,node);children+=dp[sled];
}
if (state[node-1]=='0') dp[node]=max(children,0);
else dp[node]=max(children-1,1);
}
void calculate(int node,int pret)
{
int children=suma[pret]+dp[parent[pret]]-dp[node];
if (state[pret-1]=='0') dp[pret]=max(children,0);
else dp[pret]=max(children-1,1);
children=suma[node]+dp[pret];
if (state[node-1]=='0') dp[node]=max(children,0);
else dp[node]=max(children-1,1);
answer=max(answer,max(dp[node],2));
for (int sled:adj[node])
{
if (sled!=pret) calculate(sled,node);
}
children=suma[node];
if (state[node-1]=='0') dp[node]=max(children,0);
else dp[node]=max(children-1,1);
children=suma[pret];
if (state[pret-1]=='0') dp[pret]=max(children,0);
else dp[pret]=max(children-1,1);
}
int main()
{
ios_base::sync_with_stdio(false);ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n;for (int i=1;i<n;i++) {int u,v;cin>>u>>v;adj[u].push_back(v);adj[v].push_back(u);}
cin>>state;int number=0;for (int node=0;node<n;node++) number+=(state[node]-'0');
if (number<=2) {cout<<number<<endl;return 0;}
dfs(1,0);answer=max(dp[1],2);
for (int node=1;node<=n;node++)
{
for (int sled:adj[node])
{
if (sled!=parent[node]) suma[node]+=dp[sled];
}
}
for (int node:adj[1]) calculate(node,1);
cout<<answer<<endl;return 0;
}