Task: | Snakeless path |
Sender: | louaha1 |
Submission time: | 2024-10-21 17:35:14 +0300 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.02 s | details |
#2 | WRONG ANSWER | 0.02 s | details |
#3 | WRONG ANSWER | 0.02 s | details |
#4 | WRONG ANSWER | 0.02 s | details |
#5 | WRONG ANSWER | 0.02 s | details |
#6 | WRONG ANSWER | 0.02 s | details |
#7 | WRONG ANSWER | 0.02 s | details |
#8 | WRONG ANSWER | 0.02 s | details |
#9 | WRONG ANSWER | 0.02 s | details |
#10 | WRONG ANSWER | 0.02 s | details |
#11 | WRONG ANSWER | 0.02 s | details |
#12 | WRONG ANSWER | 0.02 s | details |
#13 | WRONG ANSWER | 0.02 s | details |
#14 | WRONG ANSWER | 0.02 s | details |
#15 | WRONG ANSWER | 0.02 s | details |
#16 | WRONG ANSWER | 0.02 s | details |
#17 | WRONG ANSWER | 0.02 s | details |
#18 | WRONG ANSWER | 0.02 s | details |
#19 | WRONG ANSWER | 0.02 s | details |
#20 | WRONG ANSWER | 0.02 s | details |
#21 | WRONG ANSWER | 0.02 s | details |
#22 | WRONG ANSWER | 0.02 s | details |
#23 | WRONG ANSWER | 0.02 s | details |
#24 | WRONG ANSWER | 0.02 s | details |
#25 | WRONG ANSWER | 0.02 s | details |
#26 | WRONG ANSWER | 0.02 s | details |
#27 | WRONG ANSWER | 0.02 s | details |
#28 | WRONG ANSWER | 0.02 s | details |
#29 | WRONG ANSWER | 0.02 s | details |
#30 | WRONG ANSWER | 0.02 s | details |
#31 | WRONG ANSWER | 0.02 s | details |
#32 | WRONG ANSWER | 0.02 s | details |
#33 | WRONG ANSWER | 0.02 s | details |
#34 | WRONG ANSWER | 0.03 s | details |
#35 | WRONG ANSWER | 0.03 s | details |
#36 | WRONG ANSWER | 0.02 s | details |
#37 | WRONG ANSWER | 0.02 s | details |
#38 | WRONG ANSWER | 0.03 s | details |
#39 | WRONG ANSWER | 0.02 s | details |
#40 | WRONG ANSWER | 0.02 s | details |
#41 | WRONG ANSWER | 0.02 s | details |
#42 | WRONG ANSWER | 0.02 s | details |
#43 | WRONG ANSWER | 0.02 s | details |
#44 | WRONG ANSWER | 0.07 s | details |
#45 | WRONG ANSWER | 0.02 s | details |
#46 | WRONG ANSWER | 0.02 s | details |
#47 | WRONG ANSWER | 0.02 s | details |
#48 | WRONG ANSWER | 0.07 s | details |
#49 | WRONG ANSWER | 0.03 s | details |
#50 | WRONG ANSWER | 0.03 s | details |
#51 | WRONG ANSWER | 0.03 s | details |
#52 | WRONG ANSWER | 0.03 s | details |
#53 | WRONG ANSWER | 0.03 s | details |
#54 | WRONG ANSWER | 0.81 s | details |
#55 | WRONG ANSWER | 0.03 s | details |
#56 | WRONG ANSWER | 0.09 s | details |
#57 | WRONG ANSWER | 0.02 s | details |
#58 | WRONG ANSWER | 0.81 s | details |
#59 | WRONG ANSWER | 0.02 s | details |
#60 | WRONG ANSWER | 0.80 s | details |
#61 | WRONG ANSWER | 0.02 s | details |
#62 | WRONG ANSWER | 0.03 s | details |
#63 | WRONG ANSWER | 0.53 s | details |
#64 | WRONG ANSWER | 0.03 s | details |
#65 | WRONG ANSWER | 0.27 s | details |
#66 | WRONG ANSWER | 0.03 s | details |
#67 | WRONG ANSWER | 0.03 s | details |
#68 | WRONG ANSWER | 0.80 s | details |
#69 | WRONG ANSWER | 0.03 s | details |
#70 | WRONG ANSWER | 0.60 s | details |
#71 | WRONG ANSWER | 0.60 s | details |
#72 | WRONG ANSWER | 0.59 s | details |
#73 | WRONG ANSWER | 0.59 s | details |
#74 | WRONG ANSWER | 0.77 s | details |
#75 | WRONG ANSWER | 0.60 s | details |
#76 | WRONG ANSWER | 0.87 s | details |
#77 | WRONG ANSWER | 0.33 s | details |
#78 | WRONG ANSWER | 0.06 s | details |
#79 | WRONG ANSWER | 0.34 s | details |
#80 | WRONG ANSWER | 0.29 s | details |
#81 | WRONG ANSWER | 0.30 s | details |
#82 | WRONG ANSWER | 0.31 s | details |
#83 | WRONG ANSWER | 0.55 s | details |
#84 | WRONG ANSWER | 0.60 s | details |
#85 | WRONG ANSWER | 0.71 s | details |
#86 | WRONG ANSWER | 0.60 s | details |
#87 | WRONG ANSWER | 0.60 s | details |
#88 | WRONG ANSWER | 0.11 s | details |
#89 | WRONG ANSWER | 0.33 s | details |
Code
from collections import deque def find_path(n, m, snake_paths): # Create adjacency list adj = [[] for _ in range(n + 1)] # Fill adjacency list, ignoring snake paths for a, b in snake_paths: adj[a].append(b) adj[b].append(a) # BFS setup visited = [False] * (n + 1) parent = [-1] * (n + 1) # Start BFS from node 1 q = deque([1]) visited[1] = True while q: u = q.popleft() if u == n: break for v in adj[u]: if not visited[v]: visited[v] = True parent[v] = u q.append(v) # If we can't reach landmark n, return 0 if not visited[n]: return 0, [] # Reconstruct the path from 1 to n path = [] current = n while current != -1: path.append(current) current = parent[current] path.reverse() return len(path), path # Input n, m = map(int, input().split()) snake_paths = [tuple(map(int, input().split())) for _ in range(m)] # Get the result path_length, path = find_path(n, m, snake_paths) # Output the result if path_length == 0: print(0) else: print(path_length) print(" ".join(map(str, path)))
Test details
Test 1
Verdict: WRONG ANSWER
input |
---|
2 1 1 2 |
correct output |
---|
0 |
user output |
---|
2 1 2 |
Test 2
Verdict: WRONG ANSWER
input |
---|
3 1 1 3 |
correct output |
---|
3 1 2 3 |
user output |
---|
2 1 3 |
Test 3
Verdict: WRONG ANSWER
input |
---|
3 1 1 3 |
correct output |
---|
3 1 2 3 |
user output |
---|
2 1 3 |
Test 4
Verdict: WRONG ANSWER
input |
---|
3 1 1 3 |
correct output |
---|
3 1 2 3 |
user output |
---|
2 1 3 |
Test 5
Verdict: WRONG ANSWER
input |
---|
4 1 1 4 |
correct output |
---|
3 1 3 4 |
user output |
---|
2 1 4 |
Test 6
Verdict: WRONG ANSWER
input |
---|
4 5 1 2 1 3 1 4 2 3 ... |
correct output |
---|
0 |
user output |
---|
2 1 4 |
Test 7
Verdict: WRONG ANSWER
input |
---|
4 3 1 2 1 3 1 4 |
correct output |
---|
0 |
user output |
---|
2 1 4 |
Test 8
Verdict: WRONG ANSWER
input |
---|
4 2 1 3 2 3 |
correct output |
---|
2 1 4 |
user output |
---|
0 |
Test 9
Verdict: WRONG ANSWER
input |
---|
4 4 1 2 1 4 2 3 3 4 |
correct output |
---|
0 |
user output |
---|
2 1 4 |
Test 10
Verdict: WRONG ANSWER
input |
---|
5 6 1 2 1 4 1 5 2 5 ... |
correct output |
---|
5 1 3 2 4 5 |
user output |
---|
2 1 5 |
Test 11
Verdict: WRONG ANSWER
input |
---|
5 5 1 2 1 3 1 5 2 5 ... |
correct output |
---|
3 1 4 5 |
user output |
---|
2 1 5 |
Test 12
Verdict: WRONG ANSWER
input |
---|
5 5 1 3 1 4 1 5 3 5 ... |
correct output |
---|
3 1 2 5 |
user output |
---|
2 1 5 |
Test 13
Verdict: WRONG ANSWER
input |
---|
5 6 1 3 1 4 1 5 2 4 ... |
correct output |
---|
5 1 2 3 4 5 |
user output |
---|
2 1 5 |
Test 14
Verdict: WRONG ANSWER
input |
---|
5 9 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 5 |
Test 15
Verdict: WRONG ANSWER
input |
---|
5 7 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 5 |
Test 16
Verdict: WRONG ANSWER
input |
---|
5 1 1 5 |
correct output |
---|
3 1 4 5 |
user output |
---|
2 1 5 |
Test 17
Verdict: WRONG ANSWER
input |
---|
5 4 1 2 1 3 1 4 1 5 |
correct output |
---|
0 |
user output |
---|
2 1 5 |
Test 18
Verdict: WRONG ANSWER
input |
---|
5 9 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 5 |
Test 19
Verdict: WRONG ANSWER
input |
---|
5 4 1 2 1 3 1 4 1 5 |
correct output |
---|
0 |
user output |
---|
2 1 5 |
Test 20
Verdict: WRONG ANSWER
input |
---|
10 16 1 2 1 3 1 4 1 5 ... |
correct output |
---|
6 1 6 9 8 7 10 |
user output |
---|
2 1 10 |
Test 21
Verdict: WRONG ANSWER
input |
---|
10 16 1 2 1 3 1 4 1 5 ... |
correct output |
---|
5 1 9 8 7 10 |
user output |
---|
2 1 10 |
Test 22
Verdict: WRONG ANSWER
input |
---|
10 16 1 2 1 4 1 5 1 6 ... |
correct output |
---|
10 1 3 9 8 7 6 5 4 2 10 |
user output |
---|
2 1 10 |
Test 23
Verdict: WRONG ANSWER
input |
---|
10 16 1 3 1 4 1 5 1 6 ... |
correct output |
---|
6 1 2 9 8 7 10 |
user output |
---|
2 1 10 |
Test 24
Verdict: WRONG ANSWER
input |
---|
10 39 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 10 |
Test 25
Verdict: WRONG ANSWER
input |
---|
10 17 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 10 |
Test 26
Verdict: WRONG ANSWER
input |
---|
10 1 1 10 |
correct output |
---|
3 1 9 10 |
user output |
---|
2 1 10 |
Test 27
Verdict: WRONG ANSWER
input |
---|
10 9 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 10 |
Test 28
Verdict: WRONG ANSWER
input |
---|
10 40 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 10 |
Test 29
Verdict: WRONG ANSWER
input |
---|
10 9 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 10 |
Test 30
Verdict: WRONG ANSWER
input |
---|
100 196 1 2 1 3 1 4 1 5 ... |
correct output |
---|
31 1 60 99 98 97 96 95 94 93 92 9... |
user output |
---|
2 1 100 |
Test 31
Verdict: WRONG ANSWER
input |
---|
100 196 1 2 1 3 1 4 1 5 ... |
correct output |
---|
30 1 99 98 97 96 95 94 93 92 91 9... |
user output |
---|
2 1 100 |
Test 32
Verdict: WRONG ANSWER
input |
---|
100 196 1 2 1 3 1 4 1 5 ... |
correct output |
---|
98 1 20 99 98 97 96 95 94 93 92 9... |
user output |
---|
2 1 100 |
Test 33
Verdict: WRONG ANSWER
input |
---|
100 196 1 2 1 3 1 4 1 5 ... |
correct output |
---|
32 1 8 99 98 97 96 95 94 93 92 91... |
user output |
---|
2 1 100 |
Test 34
Verdict: WRONG ANSWER
input |
---|
100 4910 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100 |
Test 35
Verdict: WRONG ANSWER
input |
---|
100 197 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100 |
Test 36
Verdict: WRONG ANSWER
input |
---|
100 248 1 8 1 29 1 53 1 61 ... |
correct output |
---|
3 1 99 100 |
user output |
---|
2 1 100 |
Test 37
Verdict: WRONG ANSWER
input |
---|
100 99 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100 |
Test 38
Verdict: WRONG ANSWER
input |
---|
100 4888 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100 |
Test 39
Verdict: WRONG ANSWER
input |
---|
100 99 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100 |
Test 40
Verdict: WRONG ANSWER
input |
---|
200 396 1 2 1 3 1 4 1 5 ... |
correct output |
---|
60 1 119 199 198 197 196 195 194 ... |
user output |
---|
2 1 200 |
Test 41
Verdict: WRONG ANSWER
input |
---|
200 396 1 2 1 3 1 4 1 5 ... |
correct output |
---|
58 1 199 198 197 196 195 194 193 ... |
user output |
---|
2 1 200 |
Test 42
Verdict: WRONG ANSWER
input |
---|
200 396 1 2 1 3 1 4 1 5 ... |
correct output |
---|
195 1 38 199 198 197 196 195 194 1... |
user output |
---|
2 1 200 |
Test 43
Verdict: WRONG ANSWER
input |
---|
200 396 1 2 1 3 1 4 1 5 ... |
correct output |
---|
61 1 16 199 198 197 196 195 194 1... |
user output |
---|
2 1 200 |
Test 44
Verdict: WRONG ANSWER
input |
---|
200 19807 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 200 |
Test 45
Verdict: WRONG ANSWER
input |
---|
200 397 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 200 |
Test 46
Verdict: WRONG ANSWER
input |
---|
200 994 1 8 1 29 1 53 1 61 ... |
correct output |
---|
3 1 199 200 |
user output |
---|
2 1 200 |
Test 47
Verdict: WRONG ANSWER
input |
---|
200 199 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 200 |
Test 48
Verdict: WRONG ANSWER
input |
---|
200 19792 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 200 |
Test 49
Verdict: WRONG ANSWER
input |
---|
200 199 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 200 |
Test 50
Verdict: WRONG ANSWER
input |
---|
1000 1996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
288 1 593 999 998 997 996 995 994 ... |
user output |
---|
2 1 1000 |
Test 51
Verdict: WRONG ANSWER
input |
---|
1000 1996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
282 1 997 999 998 996 995 994 993 ... |
user output |
---|
2 1 1000 |
Test 52
Verdict: WRONG ANSWER
input |
---|
1000 1996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
975 1 186 999 998 997 996 995 994 ... |
user output |
---|
2 1 1000 |
Test 53
Verdict: WRONG ANSWER
input |
---|
1000 1996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
295 1 72 999 998 997 996 995 994 9... |
user output |
---|
2 1 1000 |
Test 54
Verdict: WRONG ANSWER
input |
---|
1000 299999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
3 1 691 1000 |
user output |
---|
2 1 1000 |
Test 55
Verdict: WRONG ANSWER
input |
---|
1000 1997 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 1000 |
Test 56
Verdict: WRONG ANSWER
input |
---|
1000 25751 1 8 1 29 1 53 1 61 ... |
correct output |
---|
4 1 999 998 1000 |
user output |
---|
2 1 1000 |
Test 57
Verdict: WRONG ANSWER
input |
---|
1000 999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 1000 |
Test 58
Verdict: WRONG ANSWER
input |
---|
1000 299999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
3 1 832 1000 |
user output |
---|
2 1 1000 |
Test 59
Verdict: WRONG ANSWER
input |
---|
1000 999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 1000 |
Test 60
Verdict: WRONG ANSWER
input |
---|
1000 299999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
3 1 999 1000 |
user output |
---|
2 1 1000 |
Test 61
Verdict: WRONG ANSWER
input |
---|
1000 999 1 1000 2 1000 3 1000 4 1000 ... |
correct output |
---|
0 |
user output |
---|
2 1 1000 |
Test 62
Verdict: WRONG ANSWER
input |
---|
1000 999 1 1000 2 1000 3 1000 4 1000 ... |
correct output |
---|
0 |
user output |
---|
2 1 1000 |
Test 63
Verdict: WRONG ANSWER
input |
---|
1000 195765 1 2 1 3 1 4 1 5 ... |
correct output |
---|
4 1 999 997 1000 |
user output |
---|
2 1 1000 |
Test 64
Verdict: WRONG ANSWER
input |
---|
1000 1996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
229 1 922 999 998 997 996 995 994 ... |
user output |
---|
2 1 1000 |
Test 65
Verdict: WRONG ANSWER
input |
---|
1000 92979 1 6 1 8 1 12 1 18 ... |
correct output |
---|
2 1 1000 |
user output |
---|
3 1 6 1000 |
Test 66
Verdict: WRONG ANSWER
input |
---|
1000 1997 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 1000 |
Test 67
Verdict: WRONG ANSWER
input |
---|
1000 1997 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 1000 |
Test 68
Verdict: WRONG ANSWER
input |
---|
1000 299999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
3 1 885 1000 |
user output |
---|
2 1 1000 |
Test 69
Verdict: WRONG ANSWER
input |
---|
1000 999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 1000 |
Test 70
Verdict: WRONG ANSWER
input |
---|
100000 199996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
28483 1 59286 99999 99998 99997 9999... |
user output |
---|
2 1 100000 |
Test 71
Verdict: WRONG ANSWER
input |
---|
100000 199996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
27969 1 99719 99999 99998 99997 9999... |
user output |
---|
2 1 100000 |
Test 72
Verdict: WRONG ANSWER
input |
---|
100000 199996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
97408 1 18510 99999 99998 99997 9999... |
user output |
---|
2 1 100000 |
Test 73
Verdict: WRONG ANSWER
input |
---|
100000 199996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
29187 1 7074 99999 99998 99997 99996... |
user output |
---|
2 1 100000 |
Test 74
Verdict: WRONG ANSWER
input |
---|
100000 270197 1 861 1 12080 1 39541 1 39686 ... |
correct output |
---|
3 1 99999 100000 |
user output |
---|
2 1 100000 |
Test 75
Verdict: WRONG ANSWER
input |
---|
100000 199997 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100000 |
Test 76
Verdict: WRONG ANSWER
input |
---|
100000 284253 1 23553 1 48406 1 56616 1 56899 ... |
correct output |
---|
2 1 100000 |
user output |
---|
7 1 98245 52947 41553 73798 5559... |
Test 77
Verdict: WRONG ANSWER
input |
---|
100000 99999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100000 |
Test 78
Verdict: WRONG ANSWER
input |
---|
100000 3335 1 100000 11 26761 12 80933 41 44903 ... |
correct output |
---|
3 1 99999 100000 |
user output |
---|
2 1 100000 |
Test 79
Verdict: WRONG ANSWER
input |
---|
100000 99999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100000 |
Test 80
Verdict: WRONG ANSWER
input |
---|
100000 89632 1 76350 1 97733 1 100000 2 16314 ... |
correct output |
---|
3 1 99999 100000 |
user output |
---|
2 1 100000 |
Test 81
Verdict: WRONG ANSWER
input |
---|
100000 99999 1 100000 2 100000 3 100000 4 100000 ... |
correct output |
---|
0 |
user output |
---|
2 1 100000 |
Test 82
Verdict: WRONG ANSWER
input |
---|
100000 99999 1 100000 2 100000 3 100000 4 100000 ... |
correct output |
---|
0 |
user output |
---|
2 1 100000 |
Test 83
Verdict: WRONG ANSWER
input |
---|
100000 182210 1 17827 1 55463 1 98875 1 100000 ... |
correct output |
---|
3 1 99999 100000 |
user output |
---|
2 1 100000 |
Test 84
Verdict: WRONG ANSWER
input |
---|
100000 199996 1 2 1 3 1 4 1 5 ... |
correct output |
---|
22685 1 92190 99999 99998 99997 9999... |
user output |
---|
2 1 100000 |
Test 85
Verdict: WRONG ANSWER
input |
---|
100000 244084 1 33037 1 48376 1 94522 1 100000 ... |
correct output |
---|
3 1 99999 100000 |
user output |
---|
2 1 100000 |
Test 86
Verdict: WRONG ANSWER
input |
---|
100000 199997 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100000 |
Test 87
Verdict: WRONG ANSWER
input |
---|
100000 199997 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100000 |
Test 88
Verdict: WRONG ANSWER
input |
---|
100000 22805 1 100000 2 29973 7 38479 7 77260 ... |
correct output |
---|
3 1 99999 100000 |
user output |
---|
2 1 100000 |
Test 89
Verdict: WRONG ANSWER
input |
---|
100000 99999 1 2 1 3 1 4 1 5 ... |
correct output |
---|
0 |
user output |
---|
2 1 100000 |