func_code_string: #include <bits/stdc++.h>   using namespace std;   int par[100005], val[100005];   int lefm[100005], rim[100005];   int root = 0;   vector<vector<int> > adjl;   int n;   void pre(int node) {     if (adjl[node].size() == 0) {       lefm[node] = val[node];       rim[node] = val[node];       return;     }     for (int i = (0); i < (adjl[node].size()); ++i) {       pre(adjl[node][i]);       if (val[adjl[node][i]] < val[node])         lefm[node] = lefm[adjl[node][i]];       else         rim[node] = rim[adjl[node][i]];     }   }   double res[100005];   pair<int, int> qu[100005];   void query(int node, int left, int right, long long cost, int dep) {     if (adjl[node].size() == 0) {       for (int i = (left); i < (right); ++i) res[qu[i].second] += cost * 1. / dep;       return;     }     int ind = lower_bound(qu + left, qu + right, make_pair(val[node], 0)) - qu;     if (ind > left && adjl[node].size() == 2)       query(adjl[node][0], left, ind, cost + lefm[adjl[node][1]], dep + 1);     if (ind < right && adjl[node].size() == 2)       query(adjl[node][1], ind, right, cost + rim[adjl[node][0]], dep + 1);   }   int main() {     int x, y, k;     scanf( %d , &n);     adjl.clear();     adjl.resize(n);     for (int i = (0); i < (n); ++i) {       scanf( %d %d , &x, &y);       x--;       val[i] = y;       par[i] = x;       if (x >= 0) adjl[x].push_back(i);       if (x < 0) root = i;     }     for (int i = (0); i < (adjl.size()); ++i) {       if (adjl[i].size() == 2)         if (val[adjl[i][0]] > val[adjl[i][1]]) swap(adjl[i][0], adjl[i][1]);       if (adjl[i].size() == 1) throw 2;     }     pre(root);     scanf( %d , &k);     for (int i = (0); i < (k); ++i) scanf( %d , &qu[i].first), qu[i].second = i;     sort(qu, qu + k);     query(root, 0, k, 0, 0);     for (int i = (0); i < (k); ++i) printf( %.12lf n , res[i]);     return 0;   }   