Dsa
Union Find
Medium
Power Grid Reliability
A regional power grid consists of N districts (0 to N-1). Some districts have a power plant. Districts can be connected via high-voltage links. A district is 'powered' if it is connected to at least one district that contains a power plant. Given a list of existing links and the locations of P power plants, determine the minimum number of additional links required so that every district in the region becomes powered. Assume there is at least one power plant in the network.
Example:
Input:
5 2 1
0
1 2
3 4
Explanation: N=5, M=2 links, P=1 plant at district 0. Links are (1,2) and (3,4). Components are {0}, {1,2}, {3,4}. Only {0} is powered. You need 2 links to connect {1,2} and {3,4} to {0}. Output: 2
Key concepts
union_findconnectivitygraph
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now