# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1037872 | Zicrus | Longest Trip (IOI23_longesttrip) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
typedef long long ll;
vector<vector<ll>> adj;
vector<bool> vst;
mt19937 mt;
vector<int> mxRand() {
ll n = adj.size();
ll start = mt() % n;
ll cur = start;
vector<int> res = {(int)start};
loop:
vst[cur] = true;
shuffle(adj[cur].begin(), adj[cur].end(), mt);
for (auto &e : adj[cur]) {
if (!vst[e]) {
cur = e;
res.push_back(e);
goto loop;
}
}
for (auto &e : res) vst[e] = false;
return res;
}
vector<int> longest_trip(int n, int d) {
mt = mt19937(time(0));
adj = vector<vector<ll>>(n);
vst = vector<bool>(n);
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (are_connected({i}, {j})) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
vector<int> res;
for (int i = 0; i < 100; i++) {
vector<int> nw = mxRand();
if (nw.size() > res.size()) res = nw;
}
return res;
}
#include "grader.cpp"