欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2060B.Farmer John's Card Game
Farmer John's Card Game
Farmer John's cows are playing a card game! Farmer John has a deck of cards numbered from to . He distributes cards to each of his cows.
Farmer John wants the game to be fair, so each cow should only be able to play card per round. He decides to determine a turn order, determined by a permutation of length , such that the 'th cow will be the '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 'th cow places any card from their deck on top of the center pile.
- The 'th cow places any card from their deck on top of the center pile.
- ...
- The '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 . 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 such that it is possible for all of his cows to empty their deck after playing all rounds of the game? If so, output any valid . Otherwise, output .
A permutation of length contains each integer from to exactly once
Input
The first line contains an integer () — the number of test cases.
The first line of each test case contains two integers and () — the number of cows and the number of cards each cow receives.
The following lines contain integers each – the cards received by each cow. It is guaranteed all given numbers (across all lines) are distinct and in the range from to , inclusive.
It is guaranteed the sum of over all test cases does not exceed .
Output
For each test case, output the following on a new line:
- If exists, output space-separated integers .
- Otherwise, output .
Note
In 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 $0\rightarrow1\rightarrow2\rightarrow3\rightarrow4\rightarrow5$.
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.
Samples
4
2 3
0 4 2
1 5 3
1 1
0
2 2
1 2
0 3
4 1
1
2
0
3
1 2
1
-1
3 1 2 4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |