#include "longesttrip.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
using i64 = long long;
vector<int> longest_trip(int N, int D) {
int n = N;
auto ask = [&](int x, int y) -> bool {
return are_connected(vector<int>{x}, vector<int>{y});
};
vector<int> nodes(n);
iota(nodes.begin(), nodes.end(), 0);
random_shuffle(nodes.begin(), nodes.end(), RNG());
vector<int> a{nodes[0]}, b;
for (int z = 1; z < n; ++z) {
int i = nodes[z];
if (ask(a.back(), i)) {
a.push_back(i);
} else {
b.push_back(i);
}
if (b.size() && ask(b.back(), a.back())) {
reverse(b.begin(), b.end());
for (auto j : b) {
a.push_back(j);
}
b.clear();
}
}
if (b.size() && are_connected(a, b)) {
if (are_connected(vector<int>{a.back()}, vector<int>(b.begin(), b.end())) == 0) {
int l = 1, r = b.size();
while (l <= r) {
int mid = (l + r) / 2;
if (are_connected(a, vector<int>(b.begin(), b.begin() + mid))) {
r = mid - 1;
} else {
l = mid + 1;
}
}
++r;
swap(b[r - 1], b.back());
swap(a, b);
}
if (ask(a.back(), b.back())) {
reverse(b.begin(), b.end());
}
int l = 1, r = b.size();
while (l <= r) {
int mid = (l + r) / 2;
if (are_connected(vector<int>{a.back()}, vector<int>(b.begin(), b.begin() + mid))) {
r = mid - 1;
} else {
l = mid + 1;
}
}
--l;
while (l--) {
b.push_back(b[0]);
b.erase(b.begin());
}
for (auto j : b) {
a.push_back(j);
}
b.clear();
} else {
if (a.size() < b.size()) {
swap(a, b);
}
}
return a;
}
Compilation message
In file included from /usr/include/c++/10/algorithm:62,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
from longesttrip.cpp:3:
/usr/include/c++/10/bits/stl_algo.h: In instantiation of 'void std::random_shuffle(_RAIter, _RAIter, _Generator&&) [with _RAIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Generator = long unsigned int]':
longesttrip.cpp:18:53: required from here
/usr/include/c++/10/bits/stl_algo.h:4636:48: error: expression cannot be used as a function
4636 | _RandomAccessIterator __j = __first + __rand((__i - __first) + 1);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~