Brave hero Bitaro challenges a dungeon quest.
The dungeon consists of rooms numbered from . Each room except room has exactly one parent room. The parent room of room () is room , and conversely, room is a child room of room . A room can have multiple child rooms, and room does not have a parent room.
Bitaro explores the rooms according to the following rules.
Room in the dungeon has a difficulty and a level . The level of each room does not change. The difficulty is defined as the number of already explored rooms among the rooms that can be reached by moving or more times from room towards its child rooms. For example, the difficulty of an unexplored room is , and the difficulty of room is always the number of rooms explored so far.
Every time a new room is explored, the following rules are applied to all rooms in the dungeon. Accordingly, monsters may be added to some rooms. Note that monsters can be added to already explored rooms.
Since Bitaro wants to minimize fighting, when exploring a new room, he selects the room that minimizes the total number of newly added monsters in the entire dungeon immediately after the exploration. If there are multiple such rooms, he selects the room with the smallest number.
However, Bitaro knows but does not know . To find out, he can choose and investigate one of the explorable rooms to learn its level .
Help Bitaro successfully complete the dungeon quest.
Before implementing the functions, you must include the "brave.h" header file using #include "brave.h".
You must implement the following function.
void bitaroTravel(int N, std::vector P)
int explore(int i)
int investigate(int i)
After exploring all rooms by calling the explore function a total of times, the bitaroTravel function must terminate.
After termination, if the order of exploring the rooms meets the problem's conditions, you will receive an Accepted!! verdict; otherwise, you will receive a Wrong Answer verdict.You must not execute any I/O functions in any part of the submitted source code.
| 4 | 32 | . |
| 5 | 21 | No additional constraints. |