In the year 3012, a teleport machine has been invented.
It can transport a person from a transmitter to the corresponding receiver,
even if the transmitter and the receiver are on different planets.
The most rich farmer, John, owns many planets as his farms.
However, he didn't have enough money to buy teleport machines to let him teleport from every planet to every other planet.
Therefor he designed some rules to build the teleport machines:
Here is an example. The arrows stand for the directions that John can teleport along.
One day, John's favorite cow, Mary, gets lost.
John knows that Mary must be in one of his planets, and he wants to go to every planet to find her.
Nevertheless, John wants to spend least time on teleporting, so he comes to you.
Could you find out the longest path that does not arrive any planet more than once?
Warn: 本題有 specialjudge
There are many parallel universes, so there are many test cases.
The actual number of test cases T is shown in the first line of the input.
Each test case contains two lines.
The first line of each test case has two integers N and K,
where N is the number of planets that farmer John owns and K is the teleport control number (see above).
The second line contains N integers, a1,...,aN, describing the number of cows in each planet.
1<=T<=50, 1<=N<=100000, 1<=K<=20, 1<=ai<231.
For each test case, please output two lines.
The first line contains an integer M, indicating the length of the longest path.
The second line contains M integers, describe the longest teleport path that does not arrive any planet twice.
Please use the number of cows to denote a planet.
If there are more then one longest path, you can output any of them.
2 2 1 2 4 3 7 15 35 60
2 4 2 3 15 35 60
Migrated from old NTUJ.
a127
No. | Testdata Range | Score |
---|