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 <bits/stdc++.h>
using namespace std;
vector<int> adj[404];
vector<int> longest_trip(int N, int d) {
if(d == 2){
vector<int> ans;
int u = 0; ans.push_back(u);
while(u < N - 1) {
if(are_connected({u}, {u + 1})) ans.push_back(++u);
else if(u != N - 2) {
ans.push_back(u + 2);
ans.push_back(u + 1);
u += 2;
} else {
reverse(ans.begin(), ans.end());
ans.push_back(N - 1);
u++;
}
}
return ans;
}
for(int i = 0; i < N; i++) adj[i].clear();
for(int i = 0; i < N; i++) {
for(int j = i + 1; j < N; j++) {
if(!are_connected({i}, {j})) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
for(int i = 0; i < N; i++) if((int)adj[i].size() >= (N + 1) / 2) return adj[i];
for(int i = 0; i < N; i++) sort(adj[i].begin(), adj[i].end());
bool vis[N]{}; vector<int> ans;
ans.push_back(0), vis[0] = true;
while(true) {
bool flag = false;
for(int i = 0; i < N; i++) {
if(!vis[i] && !binary_search(adj[ans.back()].begin(), adj[ans.back()].end(), i)) {
ans.push_back(i);
vis[i] = true;
flag = true;
break;
}
}
if(!flag) break;
}
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... |