Submission details
Task:Kolmijako
Sender:feenix
Submission time:2025-09-06 14:44:17 +0300
Language:Python3 (PyPy3)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.06 s1, 2, 3details
#20.06 s2, 3details
#30.06 s3details

Code

tests = int(input())

def find_next(inlist, pairs):
    if len(pairs) == 0:
        return inlist

    candidates = list(set(x for x in pairs if x[0] >= inlist[-1][1])) if len(inlist) > 0 else list(set(pairs))
    if len(candidates) == 0:
        return None

    for next in candidates:
        newpairs = list(pairs)
        newpairs.remove(next)
        newlist = inlist + [next]
        result = find_next(newlist, newpairs)
        if result is not None:
            return result

for _ in range(tests):
    paircount = int(input())
    pairs = []
    for _ in range(paircount):
        (a, b) = map(int, input().split())
        pair = (a, b)
        pairs.append(pair)
    pairs.sort(key=lambda x: x[1])
    result = find_next([], pairs)
    if result is not None:
        print('YES')
        for x in result:
            print('{} {}'.format(x[0], x[1]))
    else:
        print('NO')
        

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
15
1
2
3
4
...

correct output
NO
NO
NO
NO
YES
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 23, in <module>
    (a, b)...

Test 2

Group: 2, 3

Verdict:

input
100
1
2
3
4
...

correct output
NO
NO
NO
NO
YES
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 23, in <module>
    (a, b)...

Test 3

Group: 3

Verdict:

input
100
564
895
546
980
...

correct output
YES
188
1 6 12 7 18 13 24 19 30 25 36 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 23, in <module>
    (a, b)...