func_code_string: #include <bits/stdc++.h>   using std::sort;   struct Edge {     int v, w, next;   } e[200002];   int ecnt, h[100002];   inline void add_edge(int u, int v, int w) {     e[++ecnt] = {v, w, h[u]};     h[u] = ecnt;     e[++ecnt] = {u, w, h[v]};     h[v] = ecnt;   }   int size[100002], dis1[100002], dis2[100002], dp[100002];   int L, W;   int node[100002], cnt;   bool vis[100002];   inline int max(int x, int y) { return x > y ? x : y; }   void get_root(int u, int fa, int s, int &cur) {     size[u] = 1, dp[u] = 0;     for (int i = h[u]; i; i = e[i].next)       if (!vis[e[i].v] && e[i].v != fa)         get_root(e[i].v, u, s, cur), size[u] += size[e[i].v],             dp[u] = max(dp[u], size[e[i].v]);     dp[u] = max(dp[u], s - size[u]);     if (dp[u] < dp[cur]) cur = u;   }   void fill(int u, int fa, int w) {     size[u] = 1;     dis1[u] = dis1[fa] + w;     dis2[u] = dis2[fa] + 1;     for (int i = h[u]; i; i = e[i].next)       if (!vis[e[i].v] && e[i].v != fa)         fill(e[i].v, u, e[i].w), size[u] += size[e[i].v];   }   void get_node(int u, int fa) {     node[++cnt] = u;     for (int i = h[u]; i; i = e[i].next)       if (!vis[e[i].v] && e[i].v != fa) get_node(e[i].v, u);   }   inline bool cmp(int u, int v) { return dis1[u] < dis1[v]; }   int c[100002];   inline void add(int x, int v) {     x++;     for (; x <= 100000; x += ((x) & -(x))) c[x] += v;   }   inline int sum(int x) {     x++;     if (x <= 0) return 0;     int ans = 0;     for (; x > 0; x -= ((x) & -(x))) ans += c[x];     return ans;   }   long long Ans;   inline long long solve() {     long long ans = 0;     sort(node + 1, node + cnt + 1, cmp);     for (int i = 1; i <= cnt; i++) add(dis2[node[i]], 1);     int j = cnt;     for (int i = 1; i < j; i++) {       while (i < j && dis1[node[i]] + dis1[node[j]] > W)         add(dis2[node[j]], -1), j--;       if (i >= j) break;       add(dis2[node[i]], -1);       ans += sum(L - dis2[node[i]]);     }     add(dis2[node[j]], -1);     return ans;   }   inline void clear() { cnt = 0; }   void dfs(int u) {     dis1[u] = dis2[u] = 0;     fill(u, 0, 0);     for (int i = h[u]; i; i = e[i].next)       if (!vis[e[i].v]) get_node(e[i].v, u), Ans -= solve(), clear();     get_node(u, 0), Ans += solve(), clear();     vis[u] = 1;     for (int i = h[u]; i; i = e[i].next)       if (!vis[e[i].v]) {         int rt = 0;         get_root(e[i].v, 0, size[e[i].v], rt);         dfs(rt);       }   }   int main() {     int n, tu, tw;     dp[0] = 114514;     dis2[0] = -1;     scanf( %d%d%d , &n, &L, &W);     for (int i = 2; i <= n; i++) scanf( %d%d , &tu, &tw), add_edge(i, tu, tw);     int rt = 0;     get_root(1, 0, n, rt);     dfs(rt);     printf( %I64d , Ans);     return 0;   }   