Dungeon 2
Time limit1sMemory limit256 MB
Explore an unknown connected graph through a move-and-color oracle and report, for each i, how many room pairs have shortest-path distance exactly i.
- Level
Hard10 of 10
- Topics
- Graph, BFS, Implementation, Simulation
- Solved
- No attempts yet
Problem
Do you know the company Just Ordinary Inventions? Its business is making "just ordinary inventions".
JOI is playing the latest game developed by Just Ordinary Inventions.
This game is about exploring a dungeon made of several rooms and several paths. A path connects two different rooms in the dungeon and can be traveled in both directions. Between any two different rooms there is at most one path, and no path has the same room at both ends. It is also known that any two rooms in the dungeon can be reached from each other using some paths. The rooms look very similar, so two rooms with the same number of paths leaving them cannot be told apart just by looking at the room.
In this game, each room has a marker and a pedestal to help with clearing it. The paths leaving a room can be numbered first, second, ... with respect to the marker. The structure of the dungeon never changes during the game. Therefore, taking the path with the same number from the same room always leads to the same room. On the pedestal sits one gem whose color the player can change. The gem's color is one of color 1, color 2, ..., color X, and at the start of the game every room's gem is color 1. The gem's color does not change unless the player changes it.
JOI realized that the game would be easy to clear if he knew the structure of the dungeon, that is, which rooms are connected by which paths. But no matter what JOI tried, he could not determine the structure of the dungeon. So you have decided to write a program that determines the structure of the dungeon in JOI's place.
Write a program that explores the dungeon and determines its structure. However, JOI did not want the structure of the dungeon to be revealed completely, so instead of answering the structure directly, the program must answer, for each integer i from 1 to R, the value of "how many pairs of rooms can be traveled between using exactly i paths at minimum" (a pair with the room order swapped counts as the same pair).
To explore the dungeon, you are given a library for performing the following actions.
- Find out how many paths leave the room you are currently in.
- Find out the color of the gem on the pedestal in the room you are currently in.
- Set the color of the gem on the pedestal in the room you are currently in to a specified color (you may specify the same color as the current one). After that, choose one path leaving the room and travel along it to another room.
- Find out the number, among the paths leaving the room you are currently in, of the path you used last.
Input
The sample grading program reads the following data from standard input.
- The first line contains the integers N, X, and R separated by spaces. This means the dungeon has N rooms, room 1, room 2, ..., room N; there are X colors of gems; and the program must answer R values.
- Of the following 2N lines, line 2i - 1 (1 ≤ i ≤ N) contains the integer Di, meaning that Di paths leave room i. Line 2i (1 ≤ i ≤ N) contains Di integers Ti1, Ti2, ..., TiDi separated by spaces. This means that taking the j-th (1 ≤ j ≤ Di) path leaving room i leads to room Tij.
- Of the following R lines, line j (1 ≤ j ≤ R) contains the integer Aj. This means there are Aj pairs of rooms that can be traveled between using exactly j paths at minimum. That is, for each j (1 ≤ j ≤ R), if you call
Answerwith argumentDequal to j and argumentAequal to Aj, the sample grading program judges it correct; otherwise it judges it wrong.
The sample grading program calls the routine you write with the player's initial position set to room 1.
Output
When the program finishes running normally, the sample grading program outputs the following information on one line to standard output (the quotation marks are not actually output).
- If the answer is correct, the number of times the function Move was called is output as "
Accepted : #move = 8". - If the answer is wrong, the type of wrong answer is output as "
Wrong Answer [1]".
Constraints
Below, N is the number of rooms in the dungeon in the input data, and M is the number of paths.
- 2 ≤ N ≤ 200.
- 3 ≤ X ≤ 100.
- 1 ≤ R ≤ 200.
- 1 ≤ Di ≤ N - 1 (1 ≤ i ≤ N).
- 1 ≤ Tij ≤ N and Tij ≠ i (1 ≤ i ≤ N, 1 ≤ j ≤ Di).
- Ti1, Ti2, ..., TiDi (1 ≤ i ≤ N) are all distinct.
- For each i, j (1 ≤ i ≤ N, 1 ≤ j ≤ Di), there exists k (1 ≤ k ≤ DTij) with TTijk = i.
- Any two rooms can be reached from each other using some paths.