# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056689 | mc061 | Longest Trip (IOI23_longesttrip) | C++17 | 10 ms | 880 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>
using namespace std;
vector<int> path;
vector<int> mxpath;
int n;
set<int> have;
const int maxN = 256;
bool connected[maxN][maxN]={};
bool ans[maxN][maxN]={};
bool are_connected(vector<int> A, vector<int> B);
void dfs(int v) {
path.push_back(v);
have.insert(v);
if (path.size() == n) {
return;
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
random_shuffle(ord.begin(), ord.end());
for (int i : ord) {
if (!have.count(i)) {
bool c = false;
if (ans[v][i]) {
c = connected[v][i];
}
else {
ans[v][i] = ans[i][v] = true;
bool x = are_connected(vector<int>{i}, vector<int>{v});
connected[v][i] = connected[i][v] = x;
c = x;
}
if (c)
dfs(i);
}
if (path.size() == n) return;
}
if (path.size() == n) return;
if (path.size() > mxpath.size()) {
mxpath = path;
}
path.pop_back();
have.erase(v);
}
vector<int> longest_trip(int N, int D) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
connected[i][j] = false;
ans[i][j] = false;
}
}
n = N;
int start = 0;
path.clear();
have.clear();
vector<int> o(n);
iota(o.begin(), o.end(), 0);
random_shuffle(o.begin(), o.end());
for (int i = 0; i < n; ++i) {
path.clear();
have.clear();
dfs(o[i]);
if (path.size() == n) return path;
}
return mxpath.size() > path.size() ? mxpath : path;
}
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... |