Under construction

Still being built. Things may change

LoL Tournament

Time limit5sMemory limit512 MB

Summary
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 nn contestants in this year's LoL tournament, numbered from 1 to nn. 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 n−1n-1 rounds, and the winner of the last round is the champion. It goes like this.

  1. In round 1, the contestants numbered a1a_1 and b1b_1 compete. The loser is eliminated, and the winner advances and is renumbered n+1n+1.
  2. In round 2, the contestants numbered a2a_2 and b2b_2 compete, and the winner is renumbered n+2n+2.
  3. In general, in round ii the contestants numbered aia_i and bib_i compete, and the winner is renumbered n+in+i.

After all n−1n-1 rounds only one contestant is left, numbered 2n−12n-1. 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 nn, 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 pp, whoever the opponent is.

Input

The first line contains TT, the number of test cases.

The first line of each test case contains nn and pp separated by a space. The next n−1n-1 lines describe the tournament. The ii-th of those lines contains two integers aia_i and bib_i separated by a space.

Constraints

  • 1≤T≤51 \le T \le 5
  • 1≤n≤1051 \le n \le 10^5
  • The list [a1,a2,…,an−1,b1,b2,…,bn−1][a_1, a_2, \dots, a_{n-1}, b_1, b_2, \dots, b_{n-1}] contains no duplicates.
  • 1≤ai,bi<n+i1 \le a_i, b_i < n+i
  • 0≤p≤10 \le p \le 1
  • pp 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.

Examples2

  1. Example 1

    Input
    1
    5 0.9111111
    2 3
    1 6
    5 4
    8 7
    
    Expected output
    1 4 5
    
  2. Example 2

    Input
    1
    1 0.5000000
    
    Expected output
    1