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;
int n;
vector<int> solve1() {
bool b01 = are_connected({0}, {1});
bool b02 = are_connected({0}, {2});
vector<int> v;
if (!b01) v = {0, 2, 1};
if (!b02) v = {0, 1, 2};
if (b01 && b02) v = {1, 0, 2};
deque<int> d;
for (int i: v) d.push_back(i);
for (int i = 3; i < n; i++) {
int a = d.front(), b = d.back();
if (are_connected({a}, {i})) d.push_front(i);
else d.push_back(i);
}
v.clear();
while (d.size()) {
v.push_back(d.front());
d.pop_front();
}
return v;
}
vector<int> solve2() {
vector<int> a(1, 0);
vector<int> b(1, 1);
for (int i = 2; i < n; i++) {
if (are_connected({a.back()}, {b.back()})) {
while (b.size()) {
a.push_back(b.back());
b.pop_back();
}
b.push_back(i);
continue;
}
if (are_connected({a.back()}, {i})) a.push_back(i);
else b.push_back(i);
}
return (a.size() > b.size() ? a : b);
}
vector<int> longest_trip(int N, int D) {
n = N;
if (D > 1) return solve1();
return solve2();
}
Compilation message (stderr)
longesttrip.cpp: In function 'std::vector<int> solve1()':
longesttrip.cpp:17:28: warning: unused variable 'b' [-Wunused-variable]
17 | int a = d.front(), b = d.back();
| ^
# | 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... |