Graph + DFS
Intuition
Build Graphs based on edges array;
Calculate the max nodes number with deps <= k-1;
Loop nodes in first graph, and get nodes with deps <= k and plus t
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. Build Graphs based on edges array;
2. Calculate the max nodes number with deps <= k-1;
3. Loop nodes in first graph, and get nodes with deps <= k and plus the max nodes calculated in step 2;
# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```csharp []
public class Solution {
    private Dictionary<int, HashSet<int>> BuildGraph(int[][] edges)
    {
        Dictionary<int, HashSet<int>> g = new();
        foreach(int[] e in edges)
        {
            int u = e[0], v = e[1];
            if(!g.ContainsKey(u))
                g.Add(u, new HashSet<int>());

            if(!g.ContainsKey(v))
                g.Add(v, new HashSet<int>());

            g[u].Add(v);
            g[v].Add(u);
        }

        return g;
    }

    private int DFS(Dictionary<int, HashSet<int>> graph, int cur, int par, int steps, int count = 1)
    {
       // Console.WriteLine($"In DFS, cur is {cur}, parent is {par}, steps are {steps}");
        if(steps < 0 || cur == par)
            return 0;

        foreach(int next in graph[cur])
        {
            count += ((next == par)? 0 : DFS(graph, next, cur, steps-1));
           // Console.WriteLine($"in loop: next is {next}, count is {count}");
        }

        return count;
    }
    public int[] MaxTargetNodes(int[][] edges1, int[][] edges2, int k) {
        var g1 = BuildGraph(edges1);
        var g2 = BuildGraph(edges2);
        int n1Cnt = edges1.Length + 1, n2Cnt = edges2.Length+1;

        // Get max Count for edge path < k in graph2:
        int maxCnt2 = 0;
        for(int i = 0; i < n2Cnt; i++)
        {
            maxCnt2 = Math.Max(maxCnt2, DFS(g2, i, -1, k-1));
        }

        int[] res = new int[n1Cnt];
       // Console.WriteLine($"max Count in graph 2 is {maxCnt2}");
        for(int i = 0; i < n1Cnt; i++)
        {
            res[i] = maxCnt2 + DFS(g1, i, -1, k);
        }

        return res;
    }
}
```
['C#']