Submission details
Task:Distinct Routes
Sender:aalto26gm_010
Submission time:2026-10-19 16:54:35 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.00 sdetails
#60.01 sdetails
#70.01 sdetails
#80.01 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#110.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#150.01 sdetails

Compiler report

input/code.cpp: In function 'void adjust_weights(std::vector<int>&, std::vector<std::vector<bool> >&)':
input/code.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int i = 1; i < path.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <stack>
#include <functional>

std::vector<int> find_positive_path(int start, int end, std::vector<std::vector<int>> &edges, std::vector<std::vector<bool>> &used) {
    std::vector<bool> visited(edges.size(), false);

    std::function<std::vector<int>(int, int)> recurse = [&edges, &used, &visited, &recurse](int start, int end) -> std::vector<int> {
        if (start == end) return {end};
        
        visited[start] = true;
        std::vector<int> path;
        path.push_back(start);
        //std::cout << "Adding " << start+1 << std::endl;
        for (auto &edge : edges[start]) {
            if (visited[edge]) continue;
            if (used[start][edge]) continue;
            
            //std::cout << "Checking edge " << start+1 << " " << edge+1 << std::endl;
            std::vector<int> rescursed_path = recurse(edge, end);
            if (rescursed_path.size() > 0) {
                path.insert(path.end(), rescursed_path.begin(), rescursed_path.end());
                break;
            }
            //std::cout << "No valid path with " << edge+1 << std::endl;
        }

        if (path.size() == 1) {
            //std::cout << "Removing " << start+1 << std::endl;
            //visited[start] = false;
            return {};
        };
        //std::cout << "Found path" << std::endl;
        return path;
    };

    return recurse(start, end);
}

void adjust_weights(std::vector<int> &path, std::vector<std::vector<bool>> &used) {
    for (int i = 1; i < path.size(); ++i) {
        used[path[i-1]][path[i]] = true;
        used[path[i]][path[i-1]] = false;
    }
}

int main() {
    int n, m;
    std::cin >> n >> m;

    std::vector<std::vector<int>> edges(n);
    std::vector<std::vector<bool>> used(n, std::vector<bool>(n, true));
    for (int i = 0; i < m; ++i) {
        int a, b;
        std::cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
        used[a-1][b-1] = false;
    }

    bool is_max_flow = false;
    uint64_t max_flow = 0;
    std::vector<std::vector<int>> paths;
    while(!is_max_flow) {
        std::vector<int> path = find_positive_path(0, n-1, edges, used);
        if (path.size() == 0) {
            is_max_flow = true;
            continue;
        }
        
        adjust_weights(path, used);

        paths.push_back(path);
        max_flow++;
    }

    std::cout << max_flow << std::endl;
    for (auto &path : paths) {
        std::cout << path.size() << std::endl;
        for (auto &node : path) {
            std::cout << node+1 << " ";
        }
        std::cout << std::endl;
    }
}

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:

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
36
1 35 32 16 3 9 39 19 11 23 15 ...

Test 7

Verdict:

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
28
1 29 24 9 18 36 26 45 31 63 72...

Test 8

Verdict:

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
77
1 35 15 86 79 67 13 41 52 6 58...

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:

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

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