← Home
write a go solution for B. Farmer John's Card Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFarmer John's n cows are playing a card game! Farmer John has a deck of n*m cards numbered from 0 to n*m-1. He distributes m cards to each of his n cows.Farmer John wants the game to be fair, so each cow should only be able to play 1 card per round. He decides to determine a turn order, determined by a permutation^∗ p of length n, such that the p_i'th cow will be the i'th cow to place a card on top of the center pile in a round.In other words, the following events happen in order in each round:   The p_1'th cow places any card from their deck on top of the center pile.  The p_2'th cow places any card from their deck on top of the center pile.  ...  The p_n'th cow places any card from their deck on top of the center pile. There is a catch. Initially, the center pile contains a card numbered -1. In order to place a card, the number of the card must be greater than the number of the card on top of the center pile. Then, the newly placed card becomes the top card of the center pile. If a cow cannot place any card in their deck, the game is considered to be lost.Farmer John wonders: does there exist p such that it is possible for all of his cows to empty their deck after playing all m rounds of the game? If so, output any valid p. Otherwise, output -1.^∗A permutation of length n contains each integer from 1 to n exactly onceInputThe first line contains an integer t (1<=t<=400) — the number of test cases.The first line of each test case contains two integers n and m (1<=n*m<=2,000) — the number of cows and the number of cards each cow receives.The following n lines contain m integers each – the cards received by each cow. It is guaranteed all given numbers (across all n lines) are distinct and in the range from 0 to n*m-1, inclusive.It is guaranteed the sum of n*m over all test cases does not exceed 2,000.OutputFor each test case, output the following on a new line:  If p exists, output n space-separated integers p_1,p_2,ldots,p_n.  Otherwise, output -1. ExampleInput42 30 4 21 5 31 102 21 20 34 11203Output1 2
1
-1
3 1 2 4
NoteIn the first test case, one turn order that allows all cards to be played is by having the first cow go before the second cow. The cards played will be 0arrow1arrow2arrow3arrow4arrow5.In the second test case, there is only one cow, so having the cow play all of her cards in increasing order will empty the deck.In the third test case, it can be shown there is no valid turn order that allows all cards to be played.. Output only the code with no comments, explanation, or additional text.