PivotOJ

Keys

시간 제한: 2000ms메모리 제한: 2048MB출처: IOI 2021BOJ 22024

문제

Timothy the architect has designed a new escape game. In this game, there are nn rooms numbered from 00 to n1n - 1. Initially, each room contains exactly one key. Each key has a type, which is an integer between 00 and n1n - 1, inclusive. The type of the key in room ii (0in10 \le i \le n - 1) is r[i]r[i]. Note that multiple rooms may contain keys of the same type, i.e., the values r[i]r[i] are not necessarily distinct.

There are also mm bidirectional connectors in the game, numbered from 00 to m1m - 1. Connector jj (0jm10 \le j \le m - 1) connects a pair of different rooms u[j]u[j] and v[j]v[j]. 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 jj when they use this connector to move from room u[j]u[j] to room v[j]v[j], or vice versa. The player can only traverse connector jj if they have collected a key of type c[j]c[j] before.

At any point during the game, the player is in some room xx and can perform two types of actions:

  • collect the key in room xx, whose type is r[x]r[x] (unless they have collected it already),
  • traverse a connector jj, where either u[j]=xu[j] = x or v[j]=xv[j] = x, if the player has collected a key of type c[j]c[j] beforehand. Note that the player never discards a key they have collected.

The player starts the game in some room ss not carrying any keys. A room tt is reachable from a room ss, if the player who starts the game in room ss can perform some sequence of actions described above, and reach room tt.

For each room ii (0in10 \le i \le n - 1), denote the number of rooms reachable from room ii as p[i]p[i]. Timothy would like to know the set of indices ii that attain the minimum value of p[i]p[i] across 0in10 \le i \le n - 1.

코드를 제출하려면 로그인하세요.