#include "tree.h"
#include <cassert>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
int n;
std::vector<int> p, w;
vector<int>adj[200005];
long long dfs(int curr)
{
if(adj[curr].size()==0)
{
return 1;
}
long long cost=0;
for(auto k:adj[curr])
{
cost+=dfs(k);
}
return cost;
}
long long frunze=0;
void init(std::vector<int> P, std::vector<int> W)
{
p = P;
w = W;
n = (int)p.size();
for(int i=1;i<n;i++)
{
adj[P[i]].push_back(i);
}
frunze=dfs(0);
}
long long query(int L, int R)
{
return max(0ll,frunze*L-R)+frunze*L;
}