Submission #1305145

#TimeUsernameProblemLanguageResultExecution timeMemory
1305145nathlol2Longest Trip (IOI23_longesttrip)C++20
15 / 100
4 ms408 KiB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;

std::vector<int> longest_trip(int N, int D){
    vector<int> ans;
    if(D == 3){
        ans.resize(N);
        iota(ans.begin(), ans.end(), 0);
        return ans;
    }else if(D == 2){
        int pa[N], h1 = 0, h2 = 1;
        for(int i = 0;i<N;i++) pa[i] = -1;
        if(are_connected({0}, {1})){
            pa[1] = 0;
            for(int i = 2;i<N;i++){
                if(are_connected({i}, {h1})){
                    pa[i] = h1;
                    h1 = i;
                }else{
                    pa[i] = h2;
                    h2 = i;
                }
            }
            int id = h1;
            while(id != 0){
                ans.push_back(id);
                id = pa[id];
            }
            ans.push_back(0);
            vector<int> tmp;
            id = h2;
            while(id != 0){
                tmp.push_back(id);
                id = pa[id];
            }
            reverse(tmp.begin(), tmp.end());
            for(auto x : tmp){
                ans.push_back(x);
            }
            return ans;
        }else{
            pa[0] = 2;
            pa[1] = 2;
            for(int i = 3;i<N;i++){
                if(are_connected({i}, {h1})){
                    pa[i] = h1;
                    h1 = i;
                }else{
                    pa[i] = h2;
                    h2 = i;
                }
            }
            int id = h1;
            while(id != 2){
                ans.push_back(id);
                id = pa[id];
            }
            ans.push_back(2);
            vector<int> tmp;
            id = h2;
            while(id != 2){
                tmp.push_back(id);
                id = pa[id];
            }
            reverse(tmp.begin(), tmp.end());
            for(auto x : tmp){
                ans.push_back(x);
            }
            return ans;
        }
    }else{
        
    }
}

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:75:1: warning: control reaches end of non-void function [-Wreturn-type]
   75 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...