# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1080912 | asdasdqwer | Longest Trip (IOI23_longesttrip) | C++17 | 933 ms | 1444 KiB |
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;
std::vector<int> longest_trip(int N, int D) {
vector<vector<int>> g(N);
if (D == 3) {
vector<int> v;
for (int i=0;i<N;i++) {
v.push_back(i);
}
return v;
}
for (int i=0;i<N;i++) {
for (int j=i+1;j<N;j++) {
if (are_connected({i}, {j})) {
g[i].push_back(j);
g[j].push_back(i);
}
}
}
int tries = 17;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
for (int i=0;i<N;i++) {
shuffle(g[i].begin(), g[i].end(), rng);
}
vector<int> lng;
for (int i=0;i<tries;i++) {
vector<int> tmp;
vector<bool> vis(N, false);
function<void(int)> dfs=[&](int node) {
vis[node] = true;
tmp.push_back(node);
if (uniform_int_distribution<int>(0, 7)(rng) == 0) shuffle(g[node].begin(), g[node].end(), rng);
for (int x:g[node]) {
if (!vis[x]) {
dfs(x);
break;
}
}
};
dfs(uniform_int_distribution<int>(0, N-1)(rng));
if (lng.size() < tmp.size()) {
lng = tmp;
}
if (lng.size() == N) return lng;
}
return lng;
}
Compilation message (stderr)
# | 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... |