#C10894. Text Adventure Game: Danger and Items Challenge
Text Adventure Game: Danger and Items Challenge
Text Adventure Game: Danger and Items Challenge
You are given a map of a text-based adventure game with N rooms and bidirectional paths connecting them. Each room has an associated danger level and contains some items. You start in room 1. During the game, you will be given commands to move between rooms and perform actions. The commands are as follows:
- MOVE x: Move to room x, if it is directly connected to the current room. After moving, update the maximum danger value encountered so far.
- COLLECT: Collect all items in the current room (i.e. set the item count of that room to zero).
- DANGER: Output the highest danger level encountered on the path from the starting room to the current room.
Your task is to simulate these commands. It is guaranteed that every MOVE command is valid (i.e. room x is connected to the current room).
Note: If a command is not applicable, simply ignore it. The maximum danger level is calculated as the maximum danger level of all rooms visited from the starting room to the current room.
inputFormat
The input is provided via stdin and follows the format below:
- The first line contains two integers: N (the number of rooms) and P (the number of paths).
- The second line contains N integers representing the danger levels of the rooms (in order from room 1 to room N).
- The third line contains N integers representing the number of items in each room.
- The next P lines each contain two integers, u and v, indicating a bidirectional path between room u and room v.
- The following line contains an integer Q, the number of commands.
- The next Q lines each contain a command: either MOVE x, COLLECT, or DANGER.
outputFormat
For each DANGER command, output a line to stdout containing a single integer: the highest danger level encountered from the start to the current room.
## sample5 4
5 3 7 2 8
10 5 4 3 6
1 2
1 3
2 4
3 5
5
MOVE 2
DANGER
MOVE 4
COLLECT
DANGER
5
5
</p>