#include <bits/stdc++.h>
#include "message.h"
using namespace std;
#ifdef lisie_bimbi
#else
#define endl '\n'
#endif
typedef long long ll;
#define int long long
const ll inf = 1'000'000'000;
int n;
vector<vector<int>> v;
vector<int> w;
int l, r;
int dfs(int u, int l, int r){
int sum = 0;
int ans = 0;
for(auto i : v[u]){
ans += dfs(i, l, r);
sum += r;
}
ans += w[u] * (r - sum);
return ans;
}
void init(vector<int> p, vector<int> W){
for(int i = 1; i < n; i++){
v[p[i]].push_back(i);
}
w = W;
}
long long query(int L, int R){
return dfs(0, L, R);
}