Submission details
Task:Longest route
Sender:aalto25h_005
Submission time:2025-10-22 17:30:23 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

cc1plus: error: '::main' must return 'int'

Code

#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

//

void dfs(vector<vector<long long>> &v, vector<bool> &visited, long long start, long long end, vector<pair<long long, vector<long long>>> &solutions, vector<long long> &path) {
    visited[start] = true;
    path.push_back(start);

    if (start == end) {
        solutions.push_back({path.size(), path});
    }

    for (auto neighbour : v[start]) {
        if (not visited[neighbour])
            dfs(v, visited, neighbour, end, solutions, path);
    }
    path.pop_back();
    visited[start] = false;
}

long long main() {
    long long n, m;
    cin >> n >> m;

    vector<vector<long long>> adj(n);
    for (long long i = 0; i < m; ++i) {
        long long u, v;
        cin >> u >> v;
        adj[u-1].push_back(v-1);
    }

    // Prlong longing
    /*
    cout << "This are the connections:" << endl;
    for (long long i = 0; i < n; ++i) {
        cout << i << ": ";
        for (auto neig : adj[i])
            cout << neig << " ";
        cout << endl;
    }
    */

    // DFSs
    vector<pair<long long, vector<long long>>> solutions;
    vector<long long> path;
    vector<bool> visited(n, false);
    dfs(adj, visited, 0, n - 1, solutions, path);

    // Best solution
    auto it = max_element(solutions.begin(), solutions.end());

    // prlong long solution
    cout << (*it).first << endl;
    for (auto city : (*it).second)
        cout << city + 1 << " ";
    cout << endl;

    // Prlong longing solutions
    /*
    for (auto sol : solutions) {
        cout << "Solution size: " << sol.first << endl;
        for (auto city : sol.second)
            cout << city << " ";
        cout << endl;
    }
    */
}