# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1059710 | 2024-08-15T07:24:34 Z | mychecksedad | Longest Trip (IOI23_longesttrip) | C++17 | 0 ms | 0 KB |
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define all(x) x.begin(),x.end() #define ll long long #define ff first #define ss second #define vi vector<int> const int N = 200005; std::vector<int> longest_trip(int n, int D) { if(D == 3){ vector<int> v; for(int i = 0; i < n; ++i) v.pb(i); return v; } if(D == 2){ deque<int> v; v.pb(0); int o = -1; for(int i = 1; i < n; ++i){ bool x = are_connected(vi{0}, vi{i}); if(x){ o = i; v.pb(i); break; } } if(o == -1){ vi res; for(int i = 1; i < n; ++i){ res.pb(i); } return res; } v.pb(i); for(int i = 1; i < n; ++i){ if(o == i) continue; bool x = are_connected(vi{v[0]}, vi{i}); if(x){ v.push_front(i); }else v.pb(i); } vector<int> res(all(v)); return res; } return {}; }