# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
927558 | 2024-02-15T04:32:53 Z | aykhn | Longest Trip (IOI23_longesttrip) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; vector<int> longest_trip(int n, int d) { vector<int> used(n, 0); deque<int> dq; used[0] = 1; dq.push_back(0); if (are_connected({0}, {1})) dq.push_back(1), used[1] = 1; else dq.push_back(2), used[2] = 1; for (int i = 0; i < n; i++) { if (used[i]) continue; if (are_connected({dq.back(), i})) dq.push_back(i); else dq.push_front(i); used[i] = 1; } vector<int> res; while (!dq.empty()) res.push_back(dq.front()), dq.pop_front(); return res; }