Submission #844647

# Submission time Handle Problem Language Result Execution time Memory
844647 2023-09-05T15:35:44 Z m1nk Longest Trip (IOI23_longesttrip) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

bool check(int u,int v){
    return are_connected({u},{v});
}




vector<int> longest_trip(int n,int d){
    if(d == 1){
        vector<int> p1 = {0},p2 = {1};
        for(int i = 2;i<n;i++){
            if(check(p1.back(),i)){
                p1.push_back(i);
            }
            else if(check(p2.back(),i)){
                p2.push_back(i);
            }
            else{
                reverse(p2.begin() , p2.end());
                p1.insert(p1.end() , p2.begin() , p2.end());
                p2 = {i};
            }
        }
        if(p1.size() < p2.size()){
            swap(p1,p2);
        }
        if(p2.empty()){
            return p1;
        }
        if(!are_connected(p1,p2)){
            return p1;
        }



        if(check(p1.back() , p2[0])){
            p1.insert(p1.end() , p2.begin(), p2.end());
            return p1;
        }
        else if(check(p1[0] , p2[0])){
            reverse(p2.begin(),p2.end());
            p2.insert(p2.end(),p1.begin(),p1.end());
            return p2;
        }
        
        if(check(p2[0] , p1[0])){
            reverse(p1.begin() , p1.end());
            p1.insert(p1.end() , p2.begin() , p2.end());
            return p1;
        }
        else if(check(p2.back() , p1[0])){
            p2.insert(p2.end() , p1.begin() , p1.end());
            return p2;
        }



        for(int i = 0;i<(int)p1.size();i++){
            for(int j = 0;j<(int)p2.size();j++){
                if(check(p1[i] , p2[j])){
                    vector<int> res;
                    res.insert(res.end() , p1.begin() + i + 1,p1.end());
                    res.insert(res.end() , p1.begin() , p1.begin() + i + 1);
                    res.insert(res.end(),p2.begin() + j,p2.end());
                    res.insert(res.end() , p2.begin() , p2.begin() + j);
                    return res;
                }
            }
        }
        return p1;
    }
    else{
        vector<int> res {0};
        for(int i = 1;i<n;i++){
            if(check(i,0)){
                res.push_back(i);
                break;
            }
        }
        for(int i = 1;i<n;i++){
            if(i == res[1]){
                continue;
            }
            if(check(res.back(),i)){
                res.push_back(i);
            }
            else{
                res.insert(res.begin(),i);
            }
        }
        return res;
    }
}



Compilation message

longesttrip.cpp: In function 'bool check(int, int)':
longesttrip.cpp:5:12: error: 'are_connected' was not declared in this scope
    5 |     return are_connected({u},{v});
      |            ^~~~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:33:13: error: 'are_connected' was not declared in this scope
   33 |         if(!are_connected(p1,p2)){
      |             ^~~~~~~~~~~~~