#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define int long long
const int N=5e4+5;
int n,to[N][2],dp[N],rd[N];
ull f[N];
ull pows(int a,int b){
if(b==0)return 1;
ull res=pows(a,b>>1);
res=res*res;
if(b&1)res=res*a;
return res;
}
deque<int>q;
int lcm(int a,int b){
if(!a||!b)return a|b;
return a*b/__gcd(a,b);
}
vector<int>add(vector<int>a,vector<int>b){
vector<int>c;
int n=max(a.size(),b.size())+2;
c.resize(n);a.resize(n);b.resize(n);
for(int i=0;i<n;i++){
c[i]+=a[i]+b[i];
if(i<n-1)c[i+1]+=c[i]/10;
c[i]%=10;
}
while(c.back()==0)c.pop_back();
return c;
}
signed main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>to[i][0]>>to[i][1],rd[to[i][0]]++,rd[to[i][1]]++;
for(int i=1;i<=n;i++){
int op;
cin>>op;
if(op)swap(to[i][0],to[i][1]);
}
q.push_back(1);
dp[1]=1;f[1]=1;
while(q.size()){
int x=q.front();
q.pop_front();
if(f[x]&1)dp[x]++,f[x]<<=1;
int c=to[x][0],k=max(dp[x],dp[c]);
// cout<<x<<" "<<dp[x]<<" "<<f[x]<<endl;
if(dp[c]){
f[c]=f[c]*pows(2,k-dp[c])+(f[x]>>1)*pows(2,k-dp[x]);
}else{
f[c]=(f[x]>>1)*pows(2,k-dp[x]);
}
dp[c]=k;
rd[c]--;
if(!rd[c])q.push_back(c);
c=to[x][1],k=max(dp[x],dp[c]);
if(dp[c]){
f[c]=f[c]*pows(2,k-dp[c])+(f[x]>>1)*pows(2,k-dp[x]);
}else{
f[c]=(f[x]>>1)*pows(2,k-dp[x]);
}
dp[c]=k;
rd[c]--;
if(!rd[c])q.push_back(c);
}
vector<int>ans;
ans.push_back(1);
for(int i=1;i<dp[n+1];i++)ans=add(ans,ans);
while(ans.back()==0)ans.pop_back();
while(ans.size())cout<<ans.back(),ans.pop_back();
}