Search⌘ K
AI Features

Solution: Power Grid Maintenance

C# solution for the Power Grid Maintenance problem using the Union Find pattern.

Statement

You are given c power stations labeled from 11 to $c, and an undirected network described by connections, where each pair [u, v]means stationsuandv` are directly connected. These connections define connected components (power grids).

Initially, every station is online.

You must process queries in order. Each query is a pair [type, x] with the following meaning.

If type equals 11, perform a maintenance check for station x and return a station id as follows.
If station x is currently online, return x.
Otherwise, consider the connected component (in the original graph defined by connections) that contains x, and among the stations in that component that are currently online, return the smallest ...