Submission details
Task:Järjestys
Sender:tkok
Submission time:2025-09-07 10:38:22 +0300
Language:Python3 (PyPy3)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#10.06 s1, 4, 5details
#20.06 s1, 4, 5details
#30.06 s1, 4, 5details
#40.06 s1, 4, 5details
#50.06 s1, 4, 5details
#60.06 s1, 2, 4, 5details
#70.06 s1, 3, 4, 5details
#80.06 s1, 4, 5details
#90.06 s2, 4, 5details
#100.06 s3, 4, 5details
#110.06 s4, 5details
#120.06 s4, 5details
#130.06 s4, 5details
#140.06 s4, 5details
#150.06 s2, 5details
#160.06 s3, 5details
#170.07 s5details
#180.07 s5details
#190.06 s5details
#200.07 s5details
#210.06 s5details
#220.06 s5details

Code

import itertools
from itertools import permutations


def funktio(ketju: list, pool: list) -> list | bool:
    if not pool:
        return ketju
    kopio = [*pool]
    viimeisin_b = ketju[len(ketju) - 1][1]
    for i in range(len(kopio)):
        if kopio[i][0] < viimeisin_b:
            continue
        seuraava = kopio.pop(i)
        tulos = funktio([*ketju, seuraava], kopio)
        if tulos:
            return tulos
        kopio.insert(i, seuraava)
    return False

def main():
    t = int(input())
    while t > 0:
        # naivi kakkonen: jokaiselle oma lista seuraajista ja sitten iteroi vain mahdollisia läpi tai tule umpikujaan
        t -= 1
        n = int(input())
        parit = []
        for i in range(n):
            parit.append(tuple(int(x) for x in input().split()))

        ok = False
        for i in range(n):
            alku = parit.pop(i)
            tulos = funktio([alku], parit)
            if tulos:
                ok = True
                print("YES")
                for p in tulos:
                    print(str(p[0]) + " " + str(p[1]))
                break
            parit.insert(i, alku)
        else:
            print("NO")

main()

Test details

Test 1

Group: 1, 4, 5

Verdict:

input
100
1
74 75
1
100 43
...

correct output
YES
74 75
YES
100 43
YES
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 2

Group: 1, 4, 5

Verdict:

input
100
2
80 54
51 61
2
...

correct output
YES
51 61
80 54
YES
2 64
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 3

Group: 1, 4, 5

Verdict:

input
100
3
3 74
91 45
100 24
...

correct output
YES
3 74
100 24
91 45
YES
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 4

Group: 1, 4, 5

Verdict:

input
100
4
88 50
62 41
12 86
...

correct output
YES
12 86
88 50
62 41
66 93
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 5

Group: 1, 4, 5

Verdict:

input
100
5
82 80
80 92
5 22
...

correct output
YES
5 22
94 13
82 80
80 92
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 6

Group: 1, 2, 4, 5

Verdict:

input
100
5
34 38
26 30
1 6
...

correct output
YES
1 6
12 22
26 30
34 38
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 7

Group: 1, 3, 4, 5

Verdict:

input
100
5
50 40
28 25
51 7
...

correct output
YES
51 7
50 40
47 1
17 11
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 8

Group: 1, 4, 5

Verdict:

input
100
5
2 2
2 1
1 1
...

correct output
YES
1 2
2 1
2 1
1 1
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 9

Group: 2, 4, 5

Verdict:

input
100
100
175870020 296379324
248160539 883842002
21934885 781732852
...

correct output
NO
YES
4976156 6890135
10553287 11923223
14617057 17728163
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 10

Group: 3, 4, 5

Verdict:

input
100
100
447597377 314433951
700232436 691277009
937268439 708165426
...

correct output
YES
998963839 391778929
995772196 257222033
995754704 553123757
994629465 247775824
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 11

Group: 4, 5

Verdict:

input
100
100
1 1
1 2
2 1
...

correct output
YES
1 2
2 1
1 2
2 2
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 12

Group: 4, 5

Verdict:

input
100
100
7 1
6 3
10 9
...

correct output
YES
6 7
7 8
9 10
10 10
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 13

Group: 4, 5

Verdict:

input
100
100
51 5
85 77
91 84
...

correct output
YES
100 24
100 25
100 3
100 6
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 14

Group: 4, 5

Verdict:

input
100
100
823828194 863717310
593641073 340054211
420481158 965069109
...

correct output
YES
999289319 634855378
996775156 433726648
983657502 55234695
981890636 112877413
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 15

Group: 2, 5

Verdict:

input
100
500
88724450 89315226
266915464 267648621
189301651 189661541
...

correct output
YES
764920 1459946
1936195 2832987
3691481 4085931
4991808 5840928
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 16

Group: 3, 5

Verdict:

input
100
500
763682761 317584504
756010800 260162861
435911339 78070399
...

correct output
YES
998768285 3307355
998714926 628486754
997115613 820932481
993320616 554600893
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 17

Group: 5

Verdict:

input
100
500
2 2
2 1
1 2
...

correct output
YES
1 2
2 2
2 1
1 2
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 18

Group: 5

Verdict:

input
100
500
10 6
10 10
9 10
...

correct output
YES
2 3
3 4
4 5
5 6
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 19

Group: 5

Verdict:

input
100
500
85 87
89 70
70 92
...

correct output
YES
96 97
100 67
100 10
100 97
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 20

Group: 5

Verdict:

input
100
500
861154169 119512584
569086662 606567153
288230434 322196278
...

correct output
YES
999945324 969534372
999738857 240617694
999244114 722161553
999207839 557351400
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 21

Group: 5

Verdict:

input
100
500
116439250 401518028
280329609 193466222
674040956 209050570
...

correct output
NO
YES
773701149 773852119
987509190 315670966
977413249 510418200
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...

Test 22

Group: 5

Verdict:

input
100
500
934181189 942499518
684836806 395802802
957884803 570946201
...

correct output
YES
999772640 505132174
999111650 140844643
999028633 888134186
999020109 291046771
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 5, in <module>
    def fun...