luogu#P9343. 一曲新词酒一杯
一曲新词酒一杯
Background
Last night, I listened to songs at the pleasure house. With a pot of rough wine in hand, I looked at the bright moon by the railing. Thinking of my current situation, I did not feel lost. Instead, I was still fascinated by the joy of feasting and chanting verses. While raising my cup to the wind, I remembered a drinking-table game, and played it with my friends.
Problem Description
There are cups of wine on the table, numbered . Beside the table, there are many red paper slips with the character “wine” written on them.
Next, these cups are operated on in order for operations.
There are types of operations:
1 x: Put red slip on cup .2 x: Put red slip on each of the other cups, except cup .
Ask: after at least how many operations will every cup have at least one red slip?
Input Format
This problem has multiple test cases.
The first line contains an integer , the number of test cases.
For each test case:
- The first line contains two integers .
- The next lines each contain two integers , representing the -th operation.
Output Format
For each test case:
- If after operations there is still at least one cup without any red slip, output one line with
-1. - Otherwise, output one line with an integer, the answer.
2
3 3
1 1
1 2
1 3
3 2
1 1
2 2
3
-1
Hint
[Sample 1 Explanation]
For the first test case:
- After the -st operation, cup has red slip, cup has red slips, and cup has red slips.
- After the -nd operation, cup has red slip, cup has red slip, and cup has red slips.
- After the -rd operation, cup has red slip, cup has red slip, and cup has red slip.
[Constraints and Notes]
This problem uses bundled tests.
- Subtask 1 (20 points): .
- Subtask 2 (20 points): .
- Subtask 3 (20 points): all are equal.
- Subtask 4 (20 points): .
- Subtask 5 (20 points): no special restrictions.
For of the data, , , .
Translated by ChatGPT 5