| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 846584 | math_rabbit_1028 | Longest Trip (IOI23_longesttrip) | C++17 | 68 ms | 1768 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;
int find_connected(int v, vector<int> arr) {
if (arr.size() == 0 || !are_connected({v}, arr)) return -1;
int s = 0, e = arr.size() - 1;
while (s < e) {
int m = (s + e) / 2;
vector<int> temp;
for (int i = s; i <= m; i++) temp.push_back(arr[i]);
if (are_connected({v}, temp)) e = m;
else s = m + 1;
}
return arr[s];
}
vector<int> longest_trip(int N, int D) {
int n = N;
vector<int> res;
int ch[256]; for (int i = 0; i < n; i++) ch[i] = 0;
vector<int> path, clique;
path.push_back(0);
ch[0] = 1;
while (true) {
vector<int> temp;
for (int i = 0; i < n; i++) if (ch[i] == 0) temp.push_back(i);
int v = find_connected(path.back(), temp);
if (v == -1) break;
path.push_back(v);
ch[v] = 1;
}
for (int i = 0; i < n; i++) if (ch[i] == 0) clique.push_back(i);
bool connected = false;
if (path.size() > 0 && clique.size() > 0) connected = are_connected(path, clique);
if (connected) {
int target = find_connected(path[0], clique);
if (target != -1) {
res = path;
reverse(res.begin(), res.end());
int t = 0;
for (t = 0; t < clique.size(); t++) if (clique[t] == target) break;
swap(clique[0], clique[t]);
for (int j = 0; j < clique.size(); j++) res.push_back(clique[j]);
return res;
}
int s = path.size() - 1;
target = find_connected(path[s], clique);
if (target != -1) {
res = path;
int t = 0;
for (t = 0; t < clique.size(); t++) if (clique[t] == target) break;
swap(clique[0], clique[t]);
for (int j = 0; j < clique.size(); j++) res.push_back(clique[j]);
return res;
}
for (int i = 0; i < clique.size(); i++) {
target = find_connected(clique[i], path);
if (target == -1) continue;
swap(clique[i], clique.back());
res = clique;
while (path[0] != target) {
int front = path[0];
path.erase(path.begin());
path.push_back(front);
}
for (int k = 0; k < path.size(); k++) res.push_back(path[k]);
return res;
}
}
else {
if (path.size() > clique.size()) return path;
return clique;
}
return {}; // never reached
}
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... | ||||
