# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1049217 | Zicrus | Longest Trip (IOI23_longesttrip) | C++17 | 732 ms | 2208 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;
ll sz;
vector<int> mxRand(ll start) {
ll n = adj.size();
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;
}
void dfs(ll cur) {
vst[cur] = true;
sz++;
for (auto &e : adj[cur]) {
if (vst[e]) continue;
dfs(e);
}
}
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);
}
}
}
sz = 0;
vst = vector<bool>(n);
dfs(0);
bool comp0 = sz > n/2;
ll start = 0;
for (int i = 0; i < n; i++) {
if (comp0 != vst[i]) continue;
start = i;
break;
}
for (int i = 0; i < n; i++) {
if (comp0 != vst[i]) continue;
if (adj[i].size() == 1) start = i;
}
vst = vector<bool>(n);
vector<int> res;
for (int i = 0; i < 1; i++) {
vector<int> nw = mxRand(start);
if (nw.size() > res.size()) res = nw;
}
return res;
}
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... |