Task: | Distinct Routes |
Sender: | esya_rae |
Submission time: | 2024-10-21 17:16:54 +0300 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.04 s | details |
#2 | ACCEPTED | 0.04 s | details |
#3 | ACCEPTED | 0.10 s | details |
#4 | ACCEPTED | 0.07 s | details |
#5 | ACCEPTED | 0.04 s | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | TIME LIMIT EXCEEDED | -- | details |
#8 | TIME LIMIT EXCEEDED | -- | details |
#9 | ACCEPTED | 0.04 s | details |
#10 | ACCEPTED | 0.05 s | details |
#11 | TIME LIMIT EXCEEDED | -- | details |
#12 | TIME LIMIT EXCEEDED | -- | details |
#13 | TIME LIMIT EXCEEDED | -- | details |
#14 | TIME LIMIT EXCEEDED | -- | details |
#15 | TIME LIMIT EXCEEDED | -- | details |
Code
import math import sys sys.setrecursionlimit(10**8) def find_path(s, f, visited=None, path=None): global g, n if visited is None: visited = [False] * n if path is None: path = [] path.append(s) if s == f: return path for i, w in enumerate(g[s]): if not visited[i] and w > 0: path = find_path(i, f, visited=visited, path=path) if path: return path return None def ff(s, f): global g, n, paths res = 0 path = find_path(s, f) while path: min_flow = math.inf for i in range(len(path) - 1): a, b = path[i], path[i + 1] min_flow = min(min_flow, g[a][b]) for i in range(len(path) - 1): a, b = path[i], path[i + 1] g[a][b] -= min_flow g[b][a] += min_flow res += min_flow paths.append(path) path = find_path(s, f) n, m = map(int, input().split()) g = [[0 for _ in range(n)] for _ in range(n)] paths = [] for i in range(m): a, b = map(int, input().split()) g[a - 1][b - 1] = 1 ff(0, n - 1) print(len(paths)) for path in paths: print(len(path)) for v in path: print(v + 1, end=' ') print()
Test details
Test 1
Verdict: ACCEPTED
input |
---|
2 1 1 2 |
correct output |
---|
1 2 1 2 |
user output |
---|
1 2 1 2 |
Test 2
Verdict: ACCEPTED
input |
---|
4 2 1 2 3 4 |
correct output |
---|
0 |
user output |
---|
0 |
Test 3
Verdict: ACCEPTED
input |
---|
500 996 1 2 2 500 1 3 3 500 ... |
correct output |
---|
498 3 1 2 500 3 1 3 500 ... |
user output |
---|
498 3 1 2 500 3 1 3 500 ... Truncated |
Test 4
Verdict: ACCEPTED
input |
---|
500 499 1 2 2 3 3 4 4 5 ... |
correct output |
---|
1 500 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 500 1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 5
Verdict: ACCEPTED
input |
---|
2 1 2 1 |
correct output |
---|
0 |
user output |
---|
0 |
Test 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
40 1000 25 22 15 24 7 33 16 32 ... |
correct output |
---|
21 44 1 35 39 34 29 32 22 38 20 30 1... |
user output |
---|
(empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
input |
---|
75 1000 72 6 46 66 63 45 70 46 ... |
correct output |
---|
12 30 1 29 24 9 18 63 45 31 66 72 6 ... |
user output |
---|
(empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
input |
---|
100 1000 75 97 7 62 88 25 36 44 ... |
correct output |
---|
9 51 1 35 15 86 79 34 43 94 83 75 9... |
user output |
---|
(empty) |
Test 9
Verdict: ACCEPTED
input |
---|
3 2 1 2 2 3 |
correct output |
---|
1 3 1 2 3 |
user output |
---|
1 3 1 2 3 |
Test 10
Verdict: ACCEPTED
input |
---|
11 12 1 2 2 3 3 4 4 5 ... |
correct output |
---|
2 6 1 2 3 4 5 11 7 1 6 7 8 9 10 11 |
user output |
---|
2 6 1 2 3 4 5 11 7 1 6 7 8 9 10 11 |
Test 11
Verdict: TIME LIMIT EXCEEDED
input |
---|
8 9 1 2 2 3 3 8 1 4 ... |
correct output |
---|
2 5 1 2 6 7 8 5 1 4 5 3 8 |
user output |
---|
(empty) |
Test 12
Verdict: TIME LIMIT EXCEEDED
input |
---|
8 9 1 2 1 3 2 3 3 4 ... |
correct output |
---|
1 8 1 2 3 4 5 6 7 8 |
user output |
---|
(empty) |
Test 13
Verdict: TIME LIMIT EXCEEDED
input |
---|
7 9 1 2 1 3 2 7 3 4 ... |
correct output |
---|
3 3 1 2 7 4 1 3 5 7 ... |
user output |
---|
(empty) |
Test 14
Verdict: TIME LIMIT EXCEEDED
input |
---|
7 15 3 6 5 2 5 4 3 5 ... |
correct output |
---|
2 5 1 2 3 6 7 4 1 4 5 7 |
user output |
---|
(empty) |
Test 15
Verdict: TIME LIMIT EXCEEDED
input |
---|
500 986 244 252 224 22 81 484 273 432 ... |
correct output |
---|
116 5 1 129 142 473 500 5 1 63 158 171 500 ... |
user output |
---|
(empty) |