You are investigating a cave. The cave has
When in a room, you can identify what room you are in and see how many passages it connects to, but you cannot distinguish the passages. You want to estimate the number of passages that exist in the cave. You are allowed to do up to
- be magically teleported to a room of your choice, or
- walk through a random passage connected to the room you are in, taking you to the room at the other end of that passage.
When you decide to walk through a passage, you are unable to choose which one, because they are all alike. A passage is chosen for you uniformly at random.
You begin the investigation in an arbitrary room. Estimate the number of passages between rooms in the cave with at most
If
To pass a test set, your solution must be correct for at least 90% of the test cases in that set.
Input and Output
This is an interactive problem.
Initially, your program should read a single line containing an integer,
For each test case, your program must first read a line containing two integers
The
- A single uppercase
: this means you want to walk through a random passage. - A single uppercase
and an integer : this means you want to teleport to room . - A single uppercase
and an integer : this means you want to finish exploring and estimate that the cave contains passages.
After an estimation operation, the judge will immediately start the next test case if there is one, regardless of the correctness of your estimation. If there is no next test case, the judge will wait for you to finish without any further output.
If the judge receives an invalidly formatted line from your program at any moment, or if your
Limits
Each room has at least one passage connected to it.
Testing Tool
You can use this testing tool to test locally or on our platform. To test locally, you will need to run the tool in parallel with your code; you can use our interactive runner for that.
Instructions for the testing tool are included in comments within the tool. We encourage you to add your own test cases. Please be advised that although the testing tool is intended to simulate the judging system, it is NOT the real judging system and might behave differently.
Sample Interaction
Judge | Number of Cases | Solution |
---|---|---|
1 |
||
Case 1 | ||
5 3 (Judge gives |
||
4 1 (We start at room |
||
T 5 (Teleport to Room |
||
5 2 (It has two passageways.) |
||
W (Walk through a passage.) |
||
4 1 (We arrived at room |
||
T 1 (Teleport to Room |
||
1 3 (It has |
||
E 5 (Guess |
It can be shown that the actual number of passages is either

Note
Since test data could not be found, data for this problem was randomly generated.
Comments