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 <algorithm>
#include <random>
#include <stack>
using namespace std;
vector<int> longest_trip(int N, int D)
{
stack<int> big, small;
vector<int> nodes;
for (int i = 0; i < N; i++)
nodes.push_back(i);
random_device rd;
mt19937 g(rd());
shuffle(nodes.begin(), nodes.end(), g);
big.push(nodes[0]);
small.push(nodes[1]);
bool guarantee = false;
for (int i = 2; i < N; i++) {
if (are_connected(vector<int>{big.top()}, vector<int>{i})) {
big.push(i);
guarantee = false;
} else if (guarantee) {
small.push(i);
} else if (are_connected(vector<int>{small.top()}, vector<int>{i})) {
small.push(i);
guarantee = true;
} else {
if (small.size() == 1) guarantee = true;
while (!small.empty()) {
big.push(small.top());
small.pop();
}
small.push(i);
}
}
vector<int> ans;
stack<int> s = (big.size() < small.size()) ? small : big;
while(!s.empty()) {
ans.push_back(s.top());
s.pop();
}
return ans;
}
# | 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... |