Just in Time
Time limit2sMemory limit512 MB
Given N rooms where each room has one random outgoing tunnel, choose T in [2, N] maximizing the chance a walker starting in room 1 is not back in room 1 at time T.
- Level
Medium7 of 10
- Topics
- Probability, Math, Combinatorics, Number theory
- Solved
- No attempts yet
Problem
Hello, contestant. Let us play a game. Your coach is standing in the contest room, holding a bomb that will detonate in seconds. If it goes off inside the contest room, it destroys your team's balloons and nobody else's.
The building that holds the contest room has rooms in total. Out of each room runs exactly one tunnel to a different room, and that tunnel can be used in one direction only. If room leads to room , you can walk from to , but you cannot walk from to unless room has a tunnel of its own to room .
The bomb senses the moment your coach stops moving and detonates right then. So your coach keeps walking from room to room, and passing through one tunnel takes exactly one second. He starts in the contest room, and because each room has a single outgoing tunnel, his route is fixed by the layout of the building. The only way to save the balloons is for your coach to be somewhere other than the contest room when the bomb detonates.
You do not get the map. All I will tell you is that the tunnels were chosen uniformly at random. In exchange, you get to set , which must be an integer between and inclusive. Choose so that the chance your balloons survive is as large as possible.
Exactly one value of reaches that maximum.
Let the game begin.
Input
The first line contains one integer , the number of rooms in the building ().
Output
Print, on one line, the value of that maximizes the probability that your balloons survive.