#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 |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
non-disjoint arrays |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
non-disjoint arrays |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
non-disjoint arrays |
2 |
Halted |
0 ms |
0 KB |
- |