LoL Tournament
Time limit5sMemory limit512 MB
Given a tournament bracket where each winner is renumbered, find which starting positions give the highest chance of winning all n-1 rounds with per-round win probability p.
- Level
Medium7 of 10
- Topics
- Graph, Tree, DFS, Probability
- Solved
- No attempts yet
Problem
There are contestants in this year's LoL tournament, numbered from 1 to . You decided to join, since you are very good at Dota and you laugh a lot.
The format of this tournament is unusual. Instead of single elimination, round robin or another common format, the organizers use their own rule for deciding the winner.
The tournament has rounds, and the winner of the last round is the champion. It goes like this.
- In round 1, the contestants numbered and compete. The loser is eliminated, and the winner advances and is renumbered .
- In round 2, the contestants numbered and compete, and the winner is renumbered .
- In general, in round the contestants numbered and compete, and the winner is renumbered .
After all rounds only one contestant is left, numbered . That contestant wins the tournament.
It is not hard to see that this format is unfair. Even so, the contest is well formed: a contestant wins by winning every round he or she plays, and everyone else loses to exactly one other contestant.
You decided to work the system. You want to choose your initial number, between 1 and , so that your probability of winning the tournament is as large as possible. Which number should you take? There can be several such numbers, so print all of them in increasing order.
Your probability of winning a single round is , whoever the opponent is.
Input
The first line contains , the number of test cases.
The first line of each test case contains and separated by a space. The next lines describe the tournament. The -th of those lines contains two integers and separated by a space.
Constraints
- The list contains no duplicates.
- is written with 7 digits after the decimal point.
Output
For each test case, print one line with the initial numbers that maximize your probability of winning, in increasing order, separated by single spaces.