Keys
문제
Timothy the architect has designed a new escape game. In this game, there are rooms numbered from to . Initially, each room contains exactly one key. Each key has a type, which is an integer between and , inclusive. The type of the key in room () is . Note that multiple rooms may contain keys of the same type, i.e., the values are not necessarily distinct.
There are also bidirectional connectors in the game, numbered from to . Connector () connects a pair of different rooms and . A pair of rooms can be connected by multiple connectors.
The game is played by a single player who collects the keys and moves between the rooms by traversing the connectors. We say that the player traverses connector when they use this connector to move from room to room , or vice versa. The player can only traverse connector if they have collected a key of type before.
At any point during the game, the player is in some room and can perform two types of actions:
- collect the key in room , whose type is (unless they have collected it already),
- traverse a connector , where either or , if the player has collected a key of type beforehand. Note that the player never discards a key they have collected.
The player starts the game in some room not carrying any keys. A room is reachable from a room , if the player who starts the game in room can perform some sequence of actions described above, and reach room .
For each room (), denote the number of rooms reachable from room as . Timothy would like to know the set of indices that attain the minimum value of across .