public static long Solve_Bit_Dfs(BinaryIndexedTree bit, List <int>[] adj, int node, int n, int k) { var count = bit.Get(Math.Max(1, node - k), Math.Min(n, node + k)); bit.SetDiff(node, 1); foreach (var child in adj[node]) { count += Solve_Bit_Dfs(bit, adj, child, n, k); } bit.SetDiff(node, -1); return(count); }