Submission details
Task:Distinct Routes
Sender:aalto26gm_046
Submission time:2026-10-19 16:42:40 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.01 sdetails
#7ACCEPTED0.01 sdetails
#8ACCEPTED0.01 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.01 sdetails

Code

#include<bits/stdc++.h>
//#include<unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
#define int long long
#define die(x) return cout << x << endl, 0
#define FI first
#define SE second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef map<int,int> mpi;
typedef set<int> sti;
typedef vector<pii> vii;
typedef map<pii,int> mpii;
typedef set<pii> stii;
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int power(int x, int y) { return (!y ? 1 : power(x, y / 2) * power(x, y / 2) * (y % 2 ? x : 1)); }
int to_int(string sconvert){stringstream geek(sconvert);int xconvert = 0; geek >> xconvert; return xconvert;}
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
const int MAXN=2e5+30,MAX_LOG=30,MOD=1e9+7,INF=1e17;
const double PI = acos(-1);
int mod(int x) { return (x % MOD + MOD) % MOD; }

int n, m, q;
vi g[600];
vi org_g[600];
int visited[600];
int cap[515][515];

int dfs(int v, int flow){
    if(v == n){
        return flow;}
    visited[v] = 1;
    for(int u : g[v]){
        if(!visited[u] && cap[v][u] > 0){
            int pushed = dfs(u, min(flow, cap[v][u]));
            if(pushed > 0){
                cap[v][u] -= pushed;
                cap[u][v] += pushed;
                return pushed;
            }
        }
    }
    return 0;
}

int find_route(int v, vi &route){
    route.PB(v);
    if(v == n){
        return 1;
    }
    visited[v] = 1;
    for(int u : org_g[v]){
        if(!visited[u] && cap[v][u] == 0){
            cap[v][u] = -1;
            if(find_route(u, route)){
                return 1;
            }
            cap[v][u] = 0;
        }
    }
    route.POB();
    return 0;
}
int MAIN(){
    cin>>n>>m;
    for (int i = 0; i < m; i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].PB(u);
        org_g[u].PB(v);
        cap[u][v]++;
    }

    int flow = 0;
    while(true){
        for (int i = 0; i < 600; i++){
            visited[i]=0;
        }
        
        int push = dfs(1, INF);
        if(push == 0){
            break;
        }
        flow+= push;
    }

    cout<<flow<<endl;
    for(int i=0;i<flow;i++){
        for (int i = 0; i < 600; i++){
            visited[i] = 0;
        }
        vi route;
        find_route(1, route);

        cout<<route.size()<<endl;
        for(int j=0; j< (int)route.size(); j++){
            cout<<route[j]<<' ';
        }
        cout<<endl;
    }
 

    return 0;
}

int32_t main(){
    IOS;
    int t=1;
    //cin>>t;
    while(t--)MAIN();
    return 0;
}

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 
6
1 3 39 26 6 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
16
1 29 24 9 18 36 26 41 66 72 6 ...

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
14
1 35 63 12 55 34 81 57 3 33 47...

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