func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 5E4 + 5;   const int M = N * 17 * 17;   int n, m, q, x, y, son[N], dep[N], fa[N], g[N], l[N], tot, f[N], mark[M], to[N],       ch[M][2], sum, c[N], a[N], k, b[N];   long long ans[N], tr[M], C;   vector<int> G[N];   int dfs(int x) {     int y;     son[x] = 1;     dep[x] = dep[fa[x]] + 1;     for (int i = 0; i < G[x].size(); i++) {       son[x] += dfs(y = G[x][i]);       if (son[y] > son[g[x]]) g[x] = y;     }     return son[x];   }   void dfs2(int x, int pre) {     l[x] = ++tot;     b[tot] = x;     f[x] = pre + 1;     if (g[x]) dfs2(g[x], pre);     for (int i = 0; i < G[x].size(); i++)       if (G[x][i] != g[x]) dfs2(G[x][i], tot);   }   void push_down(int p, int l, int mid, int r, int &lc, int &rc) {     if (!mark[p]) return;     if (!lc) lc = ++sum;     if (!rc) rc = ++sum;     tr[lc] += (long long)mark[p] * (mid - l + 1), mark[lc] += mark[p];     tr[rc] += (long long)mark[p] * (r - mid), mark[rc] += mark[p];     mark[p] = 0;   }   long long get(int &p, int l, int r, int x, int y, int k) {     if (x > r || y < l) return 0;     if (!p) p = ++sum;     if (x <= l && y >= r) {       int len = r - l + 1;       tr[p] += k * len;       mark[p] += k;       return tr[p] - k * len;     }     int mid = (l + r) / 2;     push_down(p, l, mid, r, ch[p][0], ch[p][1]);     long long ans =         get(ch[p][0], l, mid, x, y, k) + get(ch[p][1], mid + 1, r, x, y, k);     tr[p] = tr[ch[p][0]] + tr[ch[p][1]];     return ans;   }   void work(int x, int v, int k) {     ans[v] += (long long)c[v] * c[v] * dep[x];     for (; x;) {       ans[v] += 2ll * k *                 (get(to[v], 1, n, f[x], l[x], k) * c[v] -                  C * (dep[x] - dep[fa[b[f[x]]]])) *                 c[v];       x = fa[b[f[x]]];     }   }   int main() {     cin >> n >> m >> q >> C;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) ans[i] = C * C * n;     for (int i = 2; i <= n; i++) {       scanf( %d , &fa[i]);       G[fa[i]].push_back(i);     }     for (int i = 1; i <= m; i++) scanf( %d , &c[i]);     dfs(1);     dfs2(1, 0);     for (int i = 1; i <= n; i++) work(i, a[i], 1);     for (int i = 1; i <= q; i++) {       scanf( %d%d , &k, &x);       if (k == 1) {         scanf( %d , &y);         work(x, a[x], -1);         work(x, y, 1);         a[x] = y;       } else         printf( %.6f n , (double)ans[x] / n);     }   }   