이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
vector<int>longest_trip(int n, int d) {
  vector<pair<int,int>>X, Y;
  vector<int>A, B;
  rep(i, n/2) if(are_connected({2*i}, {2*i+1})) X.pb({2*i, 2*i+1}); else Y.pb({2*i, 2*i+1});
  if(n%2==1) A.pb(n-1);
  for(auto i : X) {
    if(A.size()==0) {
      A.pb(i.st);
      A.pb(i.nd);
      continue;
    }
    if(B.size()==0) {
      B.pb(i.st);
      B.pb(i.nd);
      continue;
    }
    if(are_connected({A.back()}, {i.st})) {
      A.pb(i.st);
      A.pb(i.nd);
      continue;
    }
    if(are_connected({B.back()}, {i.st})) {
      B.pb(i.st);
      B.pb(i.nd);
      continue;
    }
    reverse(all(B));
    for(auto j : B) A.pb(j);
    B.clear();
    B.pb(i.st);
    B.pb(i.nd);
  }
  for(auto i : Y) {
    if(A.size()==0) {
      A.pb(i.st);
      B.pb(i.nd);
      continue;
    }
    if(!are_connected({A.back()}, {i.st})) swap(i.st, i.nd);
    A.pb(i.st);
    if(B.size()==0 || are_connected({B.back()}, {i.nd})) {
      B.pb(i.nd);
      continue;
    }
    reverse(all(B));
    for(auto j : B) A.pb(j);
    B.clear();
    B.pb(i.nd);
  }
  if(A.size()<B.size()) return B;
  return A;
}
| # | 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... |