You are given c power stations labeled from c, and an undirected network described by connections, where each pair [u, v] means stations u and v 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 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 station id. If no station in that component is online, return
If type equals x goes offline. Once a station is offline, it stays offline for the rest of the queries.
Return an array containing the results of all queries with type equal to
Constraints:
c
n connections.length
connections[i].length
u_i, v_i c
u_i v_i
queries.length
queries[i].length
queries[i][0] is either
queries[i][1] c
You are given c power stations labeled from c, and an undirected network described by connections, where each pair [u, v] means stations u and v 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 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 station id. If no station in that component is online, return
If type equals x goes offline. Once a station is offline, it stays offline for the rest of the queries.
Return an array containing the results of all queries with type equal to
Constraints:
c
n connections.length
connections[i].length
u_i, v_i c
u_i v_i
queries.length
queries[i].length
queries[i][0] is either
queries[i][1] c