#include <bits/stdc++.h>
using namespace std;
// datatypes:
#define ll long long int
// #define int long long int
#define ull unsigned long long int
#define int128 __int128_t
// I/O:
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define sin insert
#define all(x) x.begin(), x.end()
#define amhie const
#define faster \\
ios_base::sync_with_stdio(false); \\
cin.tie(0); \\
cout.tie(0);
const int N = 100005;
vector<int>adj[N], rev[N];
int to_popu[N], popu[N], child[N], par[N];
void dfs(int v) {
for (auto u : adj[v]) {
dfs(u);
to_popu[v] += to_popu[u];
child[v] += child[u];
}
}
int32_t main()
{
faster
int n, k; cin >> n;
for (int i = 2; i <= n; i++) {
int x; cin >> x;
adj[x].eb(i);
par[i] = x;
}
for (int i = 1; i <= n; i++) {
child[i] = adj[i].empty();
}
for (int i = 1; i <= n; i++)cout << child[i] << " ";
cout << '\\n';
for (int i = 1; i <= n; i++) {
cin >> popu[i];
to_popu[i] = popu[i];
}
dfs(1);
for (int i = 1; i <= n; i++) {
cout << i << " " << to_popu[i] << " " << child[i] << '\\n';
}
priority_queue<vector<int>, vector<pair<int, int>>>pq;
for (auto u : adj[1]) {
pq.push({to_popu[u], u});
}
while (!pq.empty()) {
auto [w, v] = pq.top();
pq.pop();
int par_w = popu[par[v]];
int total_w = to_popu[par[v]];
int par_child = child[par[v]];
total_w /= par_child;
int xx = child[v] * par_w;
if(xx>=)
for (auto u : adj[v]) {
}
}
}