Submission details
Task:Distinct Routes
Sender:aalto26gm_005
Submission time:2026-10-19 17:14:29 +0300
Language:Python3 (PyPy3)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.04 sdetails
#3ACCEPTED0.10 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.04 sdetails
#6ACCEPTED0.07 sdetails
#7ACCEPTED0.07 sdetails
#8ACCEPTED0.07 sdetails
#9ACCEPTED0.04 sdetails
#10ACCEPTED0.04 sdetails
#11ACCEPTED0.04 sdetails
#12ACCEPTED0.04 sdetails
#13ACCEPTED0.04 sdetails
#14ACCEPTED0.04 sdetails
#15ACCEPTED0.09 sdetails

Code

from collections import deque
#def main():
#    n, target = map(int, input().split())
#    values = list(map(int, input().split()))

#    array = [(value, i + 1) for i, value in enumerate(values)]
#    array.sort()

#    for i in range(n):
#        left = i + 1
#        right = n - 1

#        while left < right:
#            total = array[i][0] + array[left][0] + array[right][0]

#            if total == target:
#                print(array[i][1], array[left][1], array[right][1])
#                return

#            elif total < target:
#                left += 1

#            else:
#                right -= 1

#    print("IMPOSSIBLE")

def ylb():

    used_teleporter = set()

    n, m = list(map(int, input().split()))

    adjacency_list = {}

    for i in range(1, n+1):
        adjacency_list[i] = []

    for _ in range(n):
        a, b = list(map(int, input().split()))

        adjacency_list[a].append(b)
        adjacency_list[b].append(a)

    print(adjacency_list)

    def dfs(node):

        if node in visited:
            return





def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n + 1)]
    edges = []

    for _ in range(m):
        a, b = map(int, input().split())
        edges.append((a, len(graph[a])))
        graph[a].append([b, 1, len(graph[b])])
        graph[b].append([a, 0, len(graph[a]) - 1])

    flow = 0

    while True:
        parent = [None] * (n + 1)
        parent[1] = (-1, -1)
        queue = deque([1])

        while queue and parent[n] is None:
            u = queue.popleft()
            for i, (v, cap, rev) in enumerate(graph[u]):
                if cap > 0 and parent[v] is None:
                    parent[v] = (u, i)
                    queue.append(v)

        if parent[n] is None:
            break

        v = n
        while v != 1:
            u, i = parent[v]
            edge = graph[u][i]
            edge[1] -= 1
            graph[v][edge[2]][1] += 1
            v = u

        flow += 1

    used = [[] for _ in range(n + 1)]
    for u, i in edges:
        if graph[u][i][1] == 0:
            used[u].append(graph[u][i][0])

    routes = []
    for _ in range(flow):
        parent = [-1] * (n + 1)
        parent[1] = 1
        queue = deque([1])

        while queue and parent[n] == -1:
            u = queue.popleft()
            for v in used[u]:
                if parent[v] == -1:
                    parent[v] = u
                    queue.append(v)

        route = []
        v = n
        while v != 1:
            route.append(v)
            u = parent[v]
            used[u].remove(v)
            v = u

        route.append(1)
        routes.append(route[::-1])

    print(flow)
    for route in routes:
        print(len(route))
        route = map(str, route)
        print(" ".join(route))

main()

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
...

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 ...

Test 5

Verdict: ACCEPTED

input
2 1
2 1

correct output
0

user output
0

Test 6

Verdict: ACCEPTED

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
21
3
1 35 40
3
1 3 40
...

Test 7

Verdict: ACCEPTED

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
12
3
1 54 75
4
1 70 12 75
...

Test 8

Verdict: ACCEPTED

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
9
2
1 100
4
1 35 23 100
...

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: ACCEPTED

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
2
5
1 2 6 7 8
5
1 4 5 3 8

Test 12

Verdict: ACCEPTED

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
1
7
1 3 4 5 6 7 8

Test 13

Verdict: ACCEPTED

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
3
3
1 2 7
4
1 3 4 7
...

Test 14

Verdict: ACCEPTED

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
2
4
1 2 5 7
7
1 4 5 2 3 6 7

Test 15

Verdict: ACCEPTED

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
116
5
1 129 142 473 500
5
1 63 158 171 500
...