# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
853586 | Andrey | Longest Trip (IOI23_longesttrip) | C++17 | 773 ms | 1176 KiB |
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;
bool haha[1000][1000];
vector<int> longest_trip(int n, int d)
{
for(int i = 0; i < n; i++) {
haha[i][i] = false;
for(int j = i+1; j < n; j++) {
bool c = are_connected({i},{j});
haha[i][j] = c;
haha[j][i] = c;
}
}
vector<bool> bruh(n,true);
deque<int> ans;
ans.push_back(0);
bruh[0] = false;
for(int i = 1; i < n; i++) {
if(haha[0][i]) {
ans.push_back(i);
bruh[i] = false;
break;
}
}
for(int i = 2; i < n; i++) {
int p;
for(int j = 0; j < n; j++) {
if(bruh[j]) {
p = j;
}
}
int a = ans[0],b = ans[ans.size()-1];
if(haha[a][p]) {
ans.push_front(p);
bruh[p] = false;
}
else if(haha[b][p]) {
ans.push_back(p);
bruh[p] = false;
}
else {
int c = -1;
for(int j = 0; j < n; j++) {
for(int y = 0; y < n; y++) {
if(bruh[j] == false && bruh[y] == true && haha[j][y]) {
c = y;
}
}
}
if(c == -1) {
break;
}
ans.push_back(c);
bruh[c] = false;
}
}
vector<int> wut(0);
for(int i = 0; i < ans.size(); i++) {
wut.push_back(ans[i]);
}
if(ans.size() == n) {
return wut;
}
else {
if(ans.size() < n-ans.size()) {
wut.clear();
for(int i = 0; i < n; i++) {
if(bruh[i]) {
wut.push_back(i);
}
}
}
}
return wut;
}
Compilation message (stderr)
# | 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... |