Timothy the architect has designed a new escape game. In this game, there are
There are also
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
At any point during the game, the player is in some room
- 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
For each room
Implementation Details
You are to implement the following procedure:
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c)
: an array of length . For each , the key in room is of type . , : two arrays of length . For each , connector connects rooms and . : an array of length . For each , the type of key needed to traverse connector is .- This procedure should return an array
of length . For each , the value of should be if for every such that , . Otherwise, the value of should be .
Examples
Example 1
Consider the following call:
find_reachable({0, 1, 1, 2},
{0, 0, 1, 1, 3}, {1, 2, 2, 3, 1}, {0, 0, 1, 0, 2})
If the player starts the game in room
Current room | Action |
---|---|
Collect key of type |
|
Traverse connector |
|
Collect key of type |
|
Traverse connector |
|
Traverse connector |
|
Traverse connector |
Hence room
Starting room |
Reachable rooms | |
---|---|---|
The smallest value of
Example 2
find_reachable({0, 1, 1, 2, 2, 1, 2},
{0, 0, 1, 1, 2, 3, 3, 4, 4, 5},
{1, 2, 2, 3, 3, 4, 5, 5, 6, 6},
{0, 0, 1, 0, 0, 1, 2, 0, 2, 1})
The table below shows the reachable rooms:
Starting room |
Reachable rooms | |
---|---|---|
The smallest value of
Example 3
find_reachable({0, 0, 0}, {0}, {1}, {0})
The table below shows the reachable rooms:
Starting room |
Reachable rooms | |
---|---|---|
The smallest value of
Constraints
for all and for all for all
Subtasks
- (
points) for all and - (
points) - (
points) - (
points) (for all ) and (for all ) - (
points) No additional constraints.
Sample Grader
The sample grader reads the input in the following format:
- line
: - line
: - line
:
The sample grader prints the return value of find_reachable
in the following format:
- line
:
Attachment Package
The sample grader and sample test cases are available here: keys.zip.
Comments