func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, root;   int val[100000], maxl[100000], maxr[100000];   vector<int> fo[100000];   void dfs(int vr) {     if (fo[vr].size() == 0) {       maxl[vr] = maxr[vr] = val[vr];       return;     }     dfs(fo[vr][0]);     dfs(fo[vr][1]);     maxl[vr] = maxl[fo[vr][0]];     maxr[vr] = maxr[fo[vr][1]];   }   map<int, int> rev1;   map<int, int> revq, vals;   double sum[100000], pl[100000];   void dfs1(int vr, int par = -1) {     if (par == -1) {       pl[vr] = 0;       sum[vr] = 0;     } else {       pl[vr] = pl[par] + 1;       if (fo[par][0] == vr)         sum[vr] = sum[par] + maxl[fo[par][1]];       else         sum[vr] = sum[par] + maxr[fo[par][0]];     }     if (!fo[vr].empty()) {       dfs1(fo[vr][0], vr);       dfs1(fo[vr][1], vr);     }   }   vector<int> ID, IDX;   void dfs2(int vr, int f, int t) {     if (f > t) return;     if (fo[vr].size() == 0) {       for (int i = f; i <= t; ++i) IDX[i] = vr;       return;     }     int DEL = (int)(lower_bound(ID.begin() + f, ID.begin() + t + 1, val[vr]) -                     ID.begin());     dfs2(fo[vr][0], f, DEL - 1);     dfs2(fo[vr][1], DEL, t);   }   int main() {     int i, j, k, l;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       int _p, _v;       scanf( %d%d , &_p, &_v);       --_p;       if (_p < 0)         root = i;       else         fo[_p].push_back(i);       val[i] = _v;     }     for (i = 0; i < n; ++i) {       if (!fo[i].empty())         if (val[fo[i][0]] > val[i]) swap(fo[i][0], fo[i][1]);       rev1[val[i]] = i;     }     dfs(root);     dfs1(root);     int Q;     scanf( %d , &Q);     ID.resize(Q);     IDX.resize(Q);     for (i = 0; i < Q; ++i) {       scanf( %d , &ID[i]);       revq[i] = ID[i];     }     sort(ID.begin(), ID.end());     for (i = 0; i < ID.size(); ++i) vals[ID[i]] = i;     dfs2(root, 0, Q - 1);     for (i = 0; i < Q; ++i)       printf( %.12lf n , sum[IDX[vals[revq[i]]]] / pl[IDX[vals[revq[i]]]]);     return 0;   }   