CSES - Aalto Competitive Programming 2024 - wk7 - Wed - Results
Submission details
Task:Longest route
Sender:aalto2024h_007
Submission time:2024-10-23 16:56:26 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.02 sdetails
#30.02 sdetails
#40.02 sdetails
#50.02 sdetails
#60.66 sdetails
#70.65 sdetails
#80.67 sdetails
#90.65 sdetails
#100.67 sdetails
#11ACCEPTED0.60 sdetails
#120.59 sdetails
#13ACCEPTED0.02 sdetails
#140.02 sdetails
#150.48 sdetails
#16ACCEPTED0.02 sdetails
#170.46 sdetails
#180.58 sdetails
#190.02 sdetails
#200.35 sdetails
#21ACCEPTED0.02 sdetails

Code

def find_path(s, f, visited=None):
    global g, n

    path = [s]
    if s == f:
        paths[s] = path
        return path

    max_path = None
    res_path = None
    for w in g[s]:
        # print(w)
        if paths[w]:
            res_path = paths[w]
            if res_path and (not max_path or len(res_path) > len(max_path)):
                max_path = res_path
        else:
            res_path = find_path(w, f)
            if res_path and (not max_path or len(res_path) > len(max_path)):
                max_path = res_path

    path.extend(max_path)
    paths[s] = path
    # print('mp', max_path, res_path)
    return path


n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)

paths = [[] for _ in range(n)]
# print(paths)
#
# print(g)
path = find_path(0, n - 1)
# print(paths)
print(len(path))
for i in range(len(path)):
    path[i] += 1
print(*path)

Test details

Test 1

Verdict: ACCEPTED

input
10 10
2 6
1 2
4 6
5 6
...

correct output
5
1 2 5 6 10 

user output
5
1 2 5 6 10

Test 2

Verdict: ACCEPTED

input
10 10
3 9
6 5
6 9
2 8
...

correct output
4
1 2 8 10 

user output
4
1 2 8 10

Test 3

Verdict:

input
10 10
5 10
4 10
8 7
7 10
...

correct output
3
1 4 10 

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 4

Verdict:

input
10 10
8 10
2 6
2 10
7 10
...

correct output
IMPOSSIBLE

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 5

Verdict:

input
10 10
8 4
2 10
1 3
4 9
...

correct output
5
1 8 7 2 10 

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 6

Verdict:

input
100000 200000
86085 57043
45527 29537
41919 84699
95993 82082
...

correct output
IMPOSSIBLE

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 7

Verdict:

input
100000 200000
10961 53490
59843 36636
40674 66772
32618 41570
...

correct output
31
1 37239 44082 21537 90572 7332...

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  [Previous line repeated 7 more times]
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 8

Verdict:

input
100000 200000
87375 76468
38855 27547
49415 83191
38572 1524
...

correct output
35
1 91343 59014 56722 34054 3875...

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  [Previous line repeated 1 more time]
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 9

Verdict:

input
100000 200000
17973 70097
19982 80323
96486 2404
75650 63274
...

correct output
36
1 25685 90292 59380 91058 2663...

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 10

Verdict:

input
100000 200000
74343 53088
97443 7885
64807 58252
9374 33312
...

correct output
28
1 26390 15278 11333 48479 6881...

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  [Previous line repeated 2 more times]
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 11

Verdict: ACCEPTED

input
100000 199998
1 100000
1 100000
2 100000
2 100000
...

correct output
2
1 100000 

user output
2
1 100000

Test 12

Verdict:

input
100000 199998
1 2
1 2
2 3
2 3
...

correct output
100000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  [Previous line repeated 995 more times]
  File "/box/input/code.py", line 5, in find_path
    if s == f:
RecursionError: maximum recursion depth exceeded in comparison

Test 13

Verdict: ACCEPTED

input
2 1
1 2

correct output
2
1 2 

user output
2
1 2

Test 14

Verdict:

input
5 4
1 2
2 3
3 4
1 5

correct output
2
1 5 

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 15

Verdict:

input
99999 149997
1 3
3 5
5 7
7 9
...

correct output
99999
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  [Previous line repeated 995 more times]
  File "/box/input/code.py", line 5, in find_path
    if s == f:
RecursionError: maximum recursion depth exceeded in comparison

Test 16

Verdict: ACCEPTED

input
3 2
1 3
3 2

correct output
2
1 3 

user output
2
1 3

Test 17

Verdict:

input
99999 149997
1 2
2 4
4 6
6 8
...

correct output
99999
1 3 2 5 4 7 6 9 8 11 10 13 12 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  [Previous line repeated 995 more times]
  File "/box/input/code.py", line 5, in find_path
    if s == f:
RecursionError: maximum recursion depth exceeded in comparison

Test 18

Verdict:

input
100000 200000
1 2
1 3
1 4
1 5
...

correct output
IMPOSSIBLE

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  [Previous line repeated 497 more times]
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 19

Verdict:

input
5 4
2 1
3 1
1 4
1 5

correct output
2
1 5 

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 22, in find_path
    path.extend(max_path)
TypeError: 'NoneType' object is not iterable

Test 20

Verdict:

input
100000 99999
99999 100000
99998 99999
99997 99998
99996 99997
...

correct output
100000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 38, in <module>
    path = find_path(0, n - 1)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  File "/box/input/code.py", line 18, in find_path
    res_path = find_path(w, f)
  [Previous line repeated 995 more times]
  File "/box/input/code.py", line 5, in find_path
    if s == f:
RecursionError: maximum recursion depth exceeded in comparison

Test 21

Verdict: ACCEPTED

input
4 4
3 1
3 4
1 2
2 4

correct output
3
1 2 4 

user output
3
1 2 4