#3607

Power Grid Maintenance

specialist · 780 · lc medium +31 · 56.3% accepted · 526 likes · top 50%

Description

There are c power stations with unique IDs 1 to c. Bidirectional connections form groups called power grids. All stations start online.

Process two types of queries:

- [1, x]: Maintenance check on station x. If x is online it handles the check itself. If offline, the smallest-ID operational station in the same grid handles it. Return -1 if none exists.

- [2, x]: Station x goes offline.

Return results for all type-1 queries in order.

Note: Grid connectivity is preserved — taking a station offline does not disconnect the grid.

Code

1
2
3