#include <cstdio>
#include <set>
typedef long long ll; 
namespace dsu
{
	int fa[200005]; 
	inline void init(int n)
	{
		for (int i = 0; i < n; i++)
			fa[i] = i; 
	}
	int getfa(int u)
	{
		if (u == fa[u])
			return u; 
		return fa[u] = getfa(fa[u]); 
	}
}
int one[200005], zero[200005], fa[200005]; 
struct comp
{
	inline bool operator ()(const int &a, const int &b) const
	{
		ll x = (ll)one[a] * zero[b], y = (ll)one[b] * zero[a]; 
		if (x == y)
			return a < b; 
		return x < y; 
	}
}; 
std::set<int, comp> se;
int main()
{
	// freopen("AGC023-F.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	for (int i = 1; i < n; i++)
	{
		scanf("%d", fa + i);
		fa[i]--; 
	}
	dsu::init(n); 
	for (int i = 0; i < n; i++)
	{
		int x; 
		scanf("%d", &x); 
		(x ? one : zero)[i]++;
	}
	for (int i = 1; i < n; i++)
		se.insert(i);
	ll ans = 0; 
	while (!se.empty())
	{
		int u = *se.begin(); 
		se.erase(se.begin()); 
		int v = dsu::getfa(fa[u]);
		if (v)
			se.erase(v); 
		dsu::fa[u] = v; 
		ans += (ll)one[v] * zero[u]; 
		one[v] += one[u]; 
		zero[v] += zero[u]; 
		if (v)
			se.insert(v); 
	}
	printf("%lld\n", ans);
	return 0;
}
