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"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) ((int)(x).size())
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
int n, d;
map<pii, bool> mp;
bool con(int a, int b) {
if(mp.count({a,b})) return mp[{a,b}];
return mp[{a,b}]=are_connected({a},{b});
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
std::vector<int> longest_trip(int N, int D) {
mp.clear();
n=N; d=D;
if(d==3) {
vi ans;
FOR(i, 0, n) ans.pb(i);
return ans;
}
if(d==2) {
vi ins;
FOR(i, 0, n) ins.pb(i);
shuffle(ins.begin(), ins.end(), rng);
vi ans;
int st=0;
while(sz(ans)<n) {
ans.clear();
vector v(n, false);
ans.pb(ins[st]); v[ins[st]]=true;
FOR(z, 0, n-1) {
FOR(j, 0, n) {
int i=ins[j];
if(v[i]) continue;
if(con(ans.back(), i)) {
ans.pb(i);
v[i]=true;
break;
}
}
}
st++;
}
return ans;
}
vi ins;
FOR(i, 0, n) ins.pb(i);
shuffle(ins.begin(), ins.end(), rng);
vi ans;
int st=0;
while(sz(ans)<(n+1)/2) {
ans.clear();
vector v(n, false);
ans.pb(ins[st]); v[ins[st]]=true;
FOR(z, 0, n-1) {
FOR(j, 0, n) {
int i=ins[j];
if(v[i]) continue;
if(con(ans.back(), i)) {
ans.pb(i);
v[i]=true;
break;
}
}
}
st++;
}
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... |