CSES - Aalto Competitive Programming 2024 - wk7 - Mon - Results
Submission details
Task:Snakeless path
Sender:paulschulte
Submission time:2024-10-21 17:02:24 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#23ACCEPTED0.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#28ACCEPTED0.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#31ACCEPTED0.00 sdetails
#32ACCEPTED0.00 sdetails
#33ACCEPTED0.00 sdetails
#34ACCEPTED0.00 sdetails
#35ACCEPTED0.00 sdetails
#36ACCEPTED0.00 sdetails
#37ACCEPTED0.00 sdetails
#38ACCEPTED0.00 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#41ACCEPTED0.00 sdetails
#42ACCEPTED0.00 sdetails
#43ACCEPTED0.00 sdetails
#44ACCEPTED0.01 sdetails
#45ACCEPTED0.00 sdetails
#46ACCEPTED0.00 sdetails
#47ACCEPTED0.00 sdetails
#48ACCEPTED0.01 sdetails
#49ACCEPTED0.00 sdetails
#50ACCEPTED0.02 sdetails
#51ACCEPTED0.02 sdetails
#52ACCEPTED0.02 sdetails
#53ACCEPTED0.02 sdetails
#54ACCEPTED0.06 sdetails
#55ACCEPTED0.01 sdetails
#56ACCEPTED0.02 sdetails
#57ACCEPTED0.01 sdetails
#58ACCEPTED0.06 sdetails
#59ACCEPTED0.01 sdetails
#60ACCEPTED0.07 sdetails
#61ACCEPTED0.02 sdetails
#62ACCEPTED0.02 sdetails
#63ACCEPTED0.05 sdetails
#64ACCEPTED0.02 sdetails
#65ACCEPTED0.04 sdetails
#66ACCEPTED0.01 sdetails
#67ACCEPTED0.01 sdetails
#68ACCEPTED0.06 sdetails
#69ACCEPTED0.01 sdetails
#700.41 sdetails
#710.40 sdetails
#720.41 sdetails
#730.41 sdetails
#740.39 sdetails
#750.39 sdetails
#760.40 sdetails
#770.39 sdetails
#780.39 sdetails
#790.40 sdetails
#800.39 sdetails
#810.39 sdetails
#820.40 sdetails
#830.39 sdetails
#840.39 sdetails
#850.40 sdetails
#860.39 sdetails
#870.39 sdetails
#880.40 sdetails
#890.40 sdetails

Code

// ~/.vim/cpp_template.cpp
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits>

#define REP(i,a,b) for (int i = a; i < b; i++)

// Type Aliases for 1D and 2D vectors with initialization
#define vi(n, val) vector<int>(n, val) // 1D vector of ints with size n, initialized to val
#define vll(n, val) vector<long long>(n, val) // 1D vector of long longs with size n, initialized to val
#define ll long long
#define vvi(n, m, val) vector<vector<int>>(n, vector<int>(m, val)) // 2D vector of ints (n x m), initialized to val
#define vvll(n, m, val) vector<vector<long long>>(n, vector<long long>(m, val)) // 2D vector of long longs (n x m), initialized to val

#define LL_INF std::numeric_limits<long long int>::max()
#define INF std::numeric_limits<int>::max()


using namespace std;


template <typename T>
void pV(const std::vector<T>& vec, const std::string& label = "Vector") {
    std::cout << label << ": [ ";
    for (const auto& elem : vec) {
        std::cout << elem << " ";
    }
    std::cout << "]" << std::endl;
}


bool dfs(int s, int n, vector<bool> *visited, vector<int> (*adj)[], vector<int> *vals) {
    if ((*visited)[s]) return false;
    (*visited)[s] = true;
    // process node s
    if(s == n-1){
        (*vals).push_back(n-1);
        return true;
    }


    for (auto u: (*adj)[s]) {
        if(dfs(u, n, visited, adj, vals)){
            (*vals).push_back(s);
            return true;
        }

    }
    return false;
}
/*
// DEPTH-FRIRST-SEARCH
vector<int> adj[N];                                                          
vector<bool> visited(N, false);
int u, v;
for(int i = 0; i < M;i++){
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
}
*/

vector<long long> dijkstra(int N, int x, vector<vector<pair<int,int>>> *adj){
    vector<bool> processed(N, false);
    vector<long long> distance(N, LL_INF);
    priority_queue<pair<long long,int>> q;
    //for (int i = 1; i <= n; i++) distance[i] = INF;
    distance[x] = 0;
    q.push({0,x});
    while (!q.empty()) {
        int a = q.top().second; q.pop();
        if (processed[a]) continue;
        processed[a] = true;
        for (auto u : (*adj)[a]) {
            int b = u.first, w = u.second;
            if (distance[a]+w < distance[b]) {
                distance[b] = distance[a]+w;
                q.push({-distance[b],b});
            }
        }
    }
    return distance;
}


/*
DIJKSTRA
//vector<vector<pair<int,int>>> adj(N, vector<pair<int, int>>(N));
*/



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // Your code starts here
    int N, m;
    cin >> N >> m;
    int n = N;

    vector<vector<int>> adj(N, vector<int>(N, 0));//, vector<pair<int, int>>(N));
    //vector<vector<int>>(n, vector<int>(m, val))
    REP(i, 0, n){
        adj[i][i] = INF;
    }
    REP(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a][b] = INF;
        adj[b][a] = INF;
    }


    vector<int> adj_new[N];                                                          
    REP(i, 0, n){
        REP(j, 0, n){
            if(adj[i][j] == 0){
                adj_new[i].push_back(j);
            }
        }
    }


    vector<bool> visited(n, false);
    vector<int> vals;
    bool res = dfs(0, n, &visited, &adj_new, &vals);
    if(!res){
        cout << 0 << endl;
        return 0;
    }else{
        // print sol
        cout << vals.size() << endl;
        for(int i = (int)vals.size()-1; i >=0; i--){
            cout << vals[i] + 1 << " ";
        }
    }


    /*


    vector<long long> distance = dijkstra(N, 0, &adj);
    //pV(distance);

    REP(i, 0, N){
        cout << distance[i] << ' ';
    }
    cout << endl;
    
    */
    
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
2 1
1 2

correct output
0

user output
0

Test 2

Verdict: ACCEPTED

input
3 1
1 3

correct output
3
1 2 3 

user output
3
1 2 3 

Test 3

Verdict: ACCEPTED

input
3 1
1 3

correct output
3
1 2 3 

user output
3
1 2 3 

Test 4

Verdict: ACCEPTED

input
3 1
1 3

correct output
3
1 2 3 

user output
3
1 2 3 

Test 5

Verdict: ACCEPTED

input
4 1
1 4

correct output
3
1 3 4 

user output
4
1 2 3 4 

Test 6

Verdict: ACCEPTED

input
4 5
1 2
1 3
1 4
2 3
...

correct output
0

user output
0

Test 7

Verdict: ACCEPTED

input
4 3
1 2
1 3
1 4

correct output
0

user output
0

Test 8

Verdict: ACCEPTED

input
4 2
1 3
2 3

correct output
2
1 4 

user output
3
1 2 4 

Test 9

Verdict: ACCEPTED

input
4 4
1 2
1 4
2 3
3 4

correct output
0

user output
0

Test 10

Verdict: ACCEPTED

input
5 6
1 2
1 4
1 5
2 5
...

correct output
5
1 3 2 4 5 

user output
5
1 3 2 4 5 

Test 11

Verdict: ACCEPTED

input
5 5
1 2
1 3
1 5
2 5
...

correct output
3
1 4 5 

user output
3
1 4 5 

Test 12

Verdict: ACCEPTED

input
5 5
1 3
1 4
1 5
3 5
...

correct output
3
1 2 5 

user output
3
1 2 5 

Test 13

Verdict: ACCEPTED

input
5 6
1 3
1 4
1 5
2 4
...

correct output
5
1 2 3 4 5 

user output
5
1 2 3 4 5 

Test 14

Verdict: ACCEPTED

input
5 9
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 15

Verdict: ACCEPTED

input
5 7
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 16

Verdict: ACCEPTED

input
5 1
1 5

correct output
3
1 4 5 

user output
5
1 2 3 4 5 

Test 17

Verdict: ACCEPTED

input
5 4
1 2
1 3
1 4
1 5

correct output
0

user output
0

Test 18

Verdict: ACCEPTED

input
5 9
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 19

Verdict: ACCEPTED

input
5 4
1 2
1 3
1 4
1 5

correct output
0

user output
0

Test 20

Verdict: ACCEPTED

input
10 16
1 2
1 3
1 4
1 5
...

correct output
6
1 6 9 8 7 10 

user output
8
1 6 2 3 4 5 7 10 

Test 21

Verdict: ACCEPTED

input
10 16
1 2
1 3
1 4
1 5
...

correct output
5
1 9 8 7 10 

user output
9
1 9 2 3 4 5 6 7 10 

Test 22

Verdict: ACCEPTED

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

Test 23

Verdict: ACCEPTED

input
10 16
1 3
1 4
1 5
1 6
...

correct output
6
1 2 9 8 7 10 

user output
8
1 2 3 4 5 6 7 10 

Test 24

Verdict: ACCEPTED

input
10 39
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 25

Verdict: ACCEPTED

input
10 17
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 26

Verdict: ACCEPTED

input
10 1
1 10

correct output
3
1 9 10 

user output
10
1 2 3 4 5 6 7 8 9 10 

Test 27

Verdict: ACCEPTED

input
10 9
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 28

Verdict: ACCEPTED

input
10 40
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 29

Verdict: ACCEPTED

input
10 9
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 30

Verdict: ACCEPTED

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
73
1 60 2 3 4 5 6 7 8 9 10 11 12 ...
Truncated

Test 31

Verdict: ACCEPTED

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
74
1 99 2 3 4 5 6 7 8 9 10 11 12 ...
Truncated

Test 32

Verdict: ACCEPTED

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

Test 33

Verdict: ACCEPTED

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
72
1 8 2 3 4 5 6 7 9 10 11 12 13 ...
Truncated

Test 34

Verdict: ACCEPTED

input
100 4910
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 35

Verdict: ACCEPTED

input
100 197
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 36

Verdict: ACCEPTED

input
100 248
1 8
1 29
1 53
1 61
...

correct output
3
1 99 100 

user output
100
1 2 3 4 5 6 7 8 9 12 10 11 13 ...
Truncated

Test 37

Verdict: ACCEPTED

input
100 99
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 38

Verdict: ACCEPTED

input
100 4888
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 39

Verdict: ACCEPTED

input
100 99
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 40

Verdict: ACCEPTED

input
200 396
1 2
1 3
1 4
1 5
...

correct output
60
1 119 199 198 197 196 195 194 ...

user output
144
1 119 2 3 4 5 6 7 8 9 10 11 12...
Truncated

Test 41

Verdict: ACCEPTED

input
200 396
1 2
1 3
1 4
1 5
...

correct output
58
1 199 198 197 196 195 194 193 ...

user output
146
1 199 2 3 4 5 6 7 8 9 10 11 12...
Truncated

Test 42

Verdict: ACCEPTED

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

Test 43

Verdict: ACCEPTED

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
143
1 16 2 3 4 5 6 7 8 9 10 11 12 ...
Truncated

Test 44

Verdict: ACCEPTED

input
200 19807
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 45

Verdict: ACCEPTED

input
200 397
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 46

Verdict: ACCEPTED

input
200 994
1 8
1 29
1 53
1 61
...

correct output
3
1 199 200 

user output
200
1 2 3 4 6 5 7 8 9 10 11 12 13 ...
Truncated

Test 47

Verdict: ACCEPTED

input
200 199
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 48

Verdict: ACCEPTED

input
200 19792
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 49

Verdict: ACCEPTED

input
200 199
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 50

Verdict: ACCEPTED

input
1000 1996
1 2
1 3
1 4
1 5
...

correct output
288
1 593 999 998 997 996 995 994 ...

user output
716
1 593 2 3 4 5 6 7 8 9 10 11 12...
Truncated

Test 51

Verdict: ACCEPTED

input
1000 1996
1 2
1 3
1 4
1 5
...

correct output
282
1 997 999 998 996 995 994 993 ...

user output
722
1 997 2 3 4 5 6 7 8 9 10 11 12...
Truncated

Test 52

Verdict: ACCEPTED

input
1000 1996
1 2
1 3
1 4
1 5
...

correct output
975
1 186 999 998 997 996 995 994 ...

user output
29
1 186 2 3 4 5 6 7 8 9 10 11 12...

Test 53

Verdict: ACCEPTED

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
709
1 72 2 3 4 5 6 7 8 9 10 11 12 ...
Truncated

Test 54

Verdict: ACCEPTED

input
1000 299999
1 2
1 3
1 4
1 5
...

correct output
3
1 691 1000 

user output
703
1 691 369 249 749 370 245 497 ...
Truncated

Test 55

Verdict: ACCEPTED

input
1000 1997
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 56

Verdict: ACCEPTED

input
1000 25751
1 8
1 29
1 53
1 61
...

correct output
4
1 999 998 1000 

user output
999
1 2 3 5 4 6 7 8 9 10 11 12 13 ...
Truncated

Test 57

Verdict: ACCEPTED

input
1000 999
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 58

Verdict: ACCEPTED

input
1000 299999
1 2
1 3
1 4
1 5
...

correct output
3
1 832 1000 

user output
711
1 832 369 559 370 371 372 373 ...
Truncated

Test 59

Verdict: ACCEPTED

input
1000 999
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 60

Verdict: ACCEPTED

input
1000 299999
1 2
1 3
1 4
1 5
...

correct output
3
1 999 1000 

user output
1000
1 9 3 2 7 12 4 15 16 5 11 8 10...
Truncated

Test 61

Verdict: ACCEPTED

input
1000 999
1 1000
2 1000
3 1000
4 1000
...

correct output
0

user output
0

Test 62

Verdict: ACCEPTED

input
1000 999
1 1000
2 1000
3 1000
4 1000
...

correct output
0

user output
0

Test 63

Verdict: ACCEPTED

input
1000 195765
1 2
1 3
1 4
1 5
...

correct output
4
1 999 997 1000 

user output
998
1 6 4 2 3 5 7 9 8 11 12 15 14 ...
Truncated

Test 64

Verdict: ACCEPTED

input
1000 1996
1 2
1 3
1 4
1 5
...

correct output
229
1 922 999 998 997 996 995 994 ...

user output
775
1 922 2 3 4 5 6 7 8 9 10 11 12...
Truncated

Test 65

Verdict: ACCEPTED

input
1000 92979
1 6
1 8
1 12
1 18
...

correct output
2
1 1000 

user output
1000
1 2 3 4 6 5 7 8 9 10 11 13 12 ...
Truncated

Test 66

Verdict: ACCEPTED

input
1000 1997
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 67

Verdict: ACCEPTED

input
1000 1997
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 68

Verdict: ACCEPTED

input
1000 299999
1 2
1 3
1 4
1 5
...

correct output
3
1 885 1000 

user output
316
1 885 369 246 769 370 371 372 ...
Truncated

Test 69

Verdict: ACCEPTED

input
1000 999
1 2
1 3
1 4
1 5
...

correct output
0

user output
0

Test 70

Verdict:

input
100000 199996
1 2
1 3
1 4
1 5
...

correct output
28483
1 59286 99999 99998 99997 9999...

user output
(empty)

Test 71

Verdict:

input
100000 199996
1 2
1 3
1 4
1 5
...

correct output
27969
1 99719 99999 99998 99997 9999...

user output
(empty)

Test 72

Verdict:

input
100000 199996
1 2
1 3
1 4
1 5
...

correct output
97408
1 18510 99999 99998 99997 9999...

user output
(empty)

Test 73

Verdict:

input
100000 199996
1 2
1 3
1 4
1 5
...

correct output
29187
1 7074 99999 99998 99997 99996...

user output
(empty)

Test 74

Verdict:

input
100000 270197
1 861
1 12080
1 39541
1 39686
...

correct output
3
1 99999 100000 

user output
(empty)

Test 75

Verdict:

input
100000 199997
1 2
1 3
1 4
1 5
...

correct output
0

user output
(empty)

Test 76

Verdict:

input
100000 284253
1 23553
1 48406
1 56616
1 56899
...

correct output
2
1 100000 

user output
(empty)

Test 77

Verdict:

input
100000 99999
1 2
1 3
1 4
1 5
...

correct output
0

user output
(empty)

Test 78

Verdict:

input
100000 3335
1 100000
11 26761
12 80933
41 44903
...

correct output
3
1 99999 100000 

user output
(empty)

Test 79

Verdict:

input
100000 99999
1 2
1 3
1 4
1 5
...

correct output
0

user output
(empty)

Test 80

Verdict:

input
100000 89632
1 76350
1 97733
1 100000
2 16314
...

correct output
3
1 99999 100000 

user output
(empty)

Test 81

Verdict:

input
100000 99999
1 100000
2 100000
3 100000
4 100000
...

correct output
0

user output
(empty)

Test 82

Verdict:

input
100000 99999
1 100000
2 100000
3 100000
4 100000
...

correct output
0

user output
(empty)

Test 83

Verdict:

input
100000 182210
1 17827
1 55463
1 98875
1 100000
...

correct output
3
1 99999 100000 

user output
(empty)

Test 84

Verdict:

input
100000 199996
1 2
1 3
1 4
1 5
...

correct output
22685
1 92190 99999 99998 99997 9999...

user output
(empty)

Test 85

Verdict:

input
100000 244084
1 33037
1 48376
1 94522
1 100000
...

correct output
3
1 99999 100000 

user output
(empty)

Test 86

Verdict:

input
100000 199997
1 2
1 3
1 4
1 5
...

correct output
0

user output
(empty)

Test 87

Verdict:

input
100000 199997
1 2
1 3
1 4
1 5
...

correct output
0

user output
(empty)

Test 88

Verdict:

input
100000 22805
1 100000
2 29973
7 38479
7 77260
...

correct output
3
1 99999 100000 

user output
(empty)

Test 89

Verdict:

input
100000 99999
1 2
1 3
1 4
1 5
...

correct output
0

user output
(empty)