Company: HackerRank
Difficulty: medium
Maximum Edges With Special-Employee Limits An undirected simple graph has `n` employees. Some employees are special. You may add edges, but after every addition each connected component must contain at most `limit` special employees. Find the greatest possible number of added edges. Input Format The first line contains `n`, `m`, `k`, and `limit`. The next `m` lines contain existing edges. The final line contains the `k` special employee labels. Output Format Print the maximum number of edges that can be added. Constraints `1 <= n <= 200000`; the graph is simple; employee labels are 1-based; no two special employees are initially connected; `1 <= limit <= k`. Notes All employees in a component containing a special employee share that employee's hotspot. Components without special employees may be joined to any allowed component. Example For `n=5`, edges `(1,2),(2,3),(1,3)`, specials `1,4,5`, and `limit=3`, the answer is `7`.