Submission #960119

# Submission time Handle Problem Language Result Execution time Memory
960119 2024-04-09T16:57:03 Z tutis Longest Trip (IOI23_longesttrip) C++17
Compilation error
0 ms 0 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(0);

std::vector<int> longest_trip(int N, int D)
{
    vector<int>x,y;
    x.push_back(0);
    for(int i=1;i<N;i++){
        if(are_connected({0}, {i})){
            x.push_back(i);
        } else{
            y.push_back(i);
        }
    }
    if(y.size()>0 && !are_connected(x,y)){
        if(x.size()>y.size()){
            return x;
        } else{
            return y;
        }
    }
    if(y.empty()){
        vector<int>p;
        for(int i=1;i<N;i++){
            p.push_back(i);
        }
        shuffle(p.begin(),p.end());
        vector<pair<int,int>>X;
        vector<int>Y;
        while(!p.empty()){
            int x=p.back();
            p.pop_back();
            bool ok=false;
            for(auto it=p.begin();it!=p.end();it++){
                if(are_connected({x}, {*it})){
                    X.push_back({x,*it});
                    p.erase(it);
                    ok=true;
                    break;
                }
            }
            if(!ok){
                Y.push_back(x);
            }
        }
        vector<int>ans;
        vector<int>p;
        ans.push_back({1});
        for(int i=2;i<N;i++){
            p.push_back(i);
        }
        while(!p.empty()){
            shuffle(p.begin(),p.end(),rng);
            bool found=false;
            for(int i: p){
                if(are_connected({ans.back()}, {i})){
                    ans.push_back(i);
                    p.erase(find(p.begin(),p.end(), i));
                    found=true;
                    break;
                }
            }
            if(!found){
                break;
            }
        }
        ans.push_back(0);
        for(int i: p){
            ans.push_back(i);
        }
        return ans;
    }
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:29:34: error: no matching function for call to 'shuffle(std::vector<int>::iterator, std::vector<int>::iterator)'
   29 |         shuffle(p.begin(),p.end());
      |                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from longesttrip.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3748:5: note: candidate: 'template<class _RAIter, class _UGenerator> void std::shuffle(_RAIter, _RAIter, _UGenerator&&)'
 3748 |     shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~~~~
/usr/include/c++/10/bits/stl_algo.h:3748:5: note:   template argument deduction/substitution failed:
longesttrip.cpp:29:34: note:   candidate expects 3 arguments, 2 provided
   29 |         shuffle(p.begin(),p.end());
      |                                  ^
longesttrip.cpp:49:20: error: redeclaration of 'std::vector<int> p'
   49 |         vector<int>p;
      |                    ^
longesttrip.cpp:25:20: note: 'std::vector<int> p' previously declared here
   25 |         vector<int>p;
      |                    ^
longesttrip.cpp:8:16: warning: control reaches end of non-void function [-Wreturn-type]
    8 |     vector<int>x,y;
      |                ^