func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<int> v[100146];   int val[100146], a[100146], b[100146];   long long cnt[1 << 18], sum[1 << 18];   int leftError[100146], rightError[100146];   void countDps(int e) {     if (v[e].size() == 0)       leftError[e] = rightError[e] = val[e];     else {       countDps(v[e][0]);       countDps(v[e][1]);       if (val[v[e][0]] < val[v[e][1]]) {         leftError[e] = leftError[v[e][0]];         rightError[e] = rightError[v[e][1]];       } else {         leftError[e] = leftError[v[e][1]];         rightError[e] = rightError[v[e][0]];       }     }   }   void add(long long* tree, int cur, int l, int r, int cl, int cr, long long c) {     if (r < cl || cr < l) return;     if (cl <= l && r <= cr)       tree[cur] += c;     else {       int mid = (l + r) / 2;       add(tree, cur * 2, l, mid, cl, cr, c);       add(tree, cur * 2 + 1, mid + 1, r, cl, cr, c);     }   }   void addToSegment(long long* tree, int l, int r, long long c) {     if (l > r) return;     add(tree, 1, 0, (1 << 17) - 1, l, r, c);   }   void dfs(int e, int l, int r) {     if (v[e].size() == 0) return;     int mid = lower_bound(a + l, a + r, val[e]) - a;     if (val[v[e][0]] < val[v[e][1]]) {       dfs(v[e][0], l, mid);       dfs(v[e][1], mid, r);       addToSegment(cnt, l, mid - 1, 1);       addToSegment(sum, l, mid - 1, leftError[v[e][1]]);       addToSegment(cnt, mid, r - 1, 1);       addToSegment(sum, mid, r - 1, rightError[v[e][0]]);     } else {       dfs(v[e][1], l, mid);       dfs(v[e][0], mid, r);       addToSegment(cnt, l, mid - 1, 1);       addToSegment(sum, l, mid - 1, leftError[v[e][0]]);       addToSegment(cnt, mid, r - 1, 1);       addToSegment(sum, mid, r - 1, rightError[v[e][1]]);     }   }   long long getValue(long long* tree, int el) {     long long cur = el + (1 << 17);     long long ans = 0;     while (cur) {       ans += tree[cur];       cur /= 2;     }     return ans;   }   int main() {     int n;     scanf( %d , &n);     int root = -1;     for (int i = 0; i < n; i++) {       int p;       scanf( %d%d , &p, &val[i]);       if (p != -1)         v[p - 1].push_back(i);       else         root = i;     }     int m;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d , &a[i]);       b[i] = a[i];     }     sort(a, a + m);     countDps(root);     memset(sum, 0, sizeof(sum));     memset(cnt, 0, sizeof(cnt));     dfs(root, 0, m);     for (int i = 0; i < m; i++) {       int ind = lower_bound(a, a + m, b[i]) - a;       double ans = (double)getValue(sum, ind) / getValue(cnt, ind);       printf( %.9lf n , ans);     }   }   