This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> longest_trip(int N, int D)
{
    vector<int> path = {0};
    vector<bool> inside(N, false);
    inside[0] = true;
    while (true) {
        if (path.size() == N) {
            return path;
        }
        bool found = false;
        for (int i = 0; i < N && !found; ++i) {
            if (!inside[i]) {
                if (are_connected({path[0]}, {i})) {
                    path.insert(path.begin(), i);
                    found = true;
                    inside[i] = true;
                    break;
                }
                if (are_connected({path[path.size() - 1]}, {i})) {
                    path.insert(path.end(), i);
                    found = true;
                    inside[i] = true;
                    break;
                }
                for (int j = 0; j < path.size(); ++j) {
                    if (are_connected({path[j]}, {i})) {
                        vector<int> new_path;
                        new_path.insert(new_path.end(), path.begin() + j + 1, path.end());
                        new_path.insert(new_path.end(), path.begin(), path.begin() + j + 1);
                        path = new_path;
                        path.insert(path.end(), i);
                        found = true;
                        inside[i] = true;
                        break;
                    }
                }
            }
        }
        if (!found) {
            if (path.size() >= (N - path.size())) {
                return path;
            }
            path.clear();
            for (int i = 0; i < N; ++i) {
                if (!inside[i]) {
                    path.insert(path.end(), i);
                }
            }
            return path;
        }
    }
}
Compilation message (stderr)
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:12:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   12 |         if (path.size() == N) {
      |             ~~~~~~~~~~~~^~~~
longesttrip.cpp:30:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |                 for (int j = 0; j < path.size(); ++j) {
      |                                 ~~^~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |