Submission #853590

#TimeUsernameProblemLanguageResultExecution timeMemory
853590AndreyLongest Trip (IOI23_longesttrip)C++17
60 / 100
862 ms1368 KiB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;

bool haha[1000][1000];

vector<int> longest_trip(int n, int d)
{
    for(int i = 0; i < n; i++) {
        haha[i][i] = false;
        for(int j = i+1; j < n; j++) {
            bool c = are_connected({i},{j});
            haha[i][j] = c;
            haha[j][i] = c;
        }
    }
    vector<bool> bruh(n,true);
    deque<int> ans;
    ans.push_back(0);
    bruh[0] = false;
    for(int i = 1; i < n; i++) {
        if(haha[0][i]) {
            ans.push_back(i);
            bruh[i] = false;
            break;
        }
    }
    if(ans.size() > 1) {
        for(int i = 2; i < n; i++) {
            int p;
            for(int j = 0; j < n; j++) {
                if(bruh[j]) {
                    p = j;
                }
            }
            int a = ans[0],b = ans[ans.size()-1];
            if(haha[a][p]) {
                ans.push_front(p);
                bruh[p] = false;
            }
            else if(haha[b][p]) {
                ans.push_back(p);
                bruh[p] = false;
            }
            else {
                int c = -1,d;
                for(int j = 0; j < n; j++) {
                    for(int y = 0; y < n; y++) {
                        if(bruh[j] == false && bruh[y] == true && haha[j][y]) {
                            c = y;
                            d = j;
                        }
                    }
                }
                if(c == -1) {
                    break;
                }
                while(ans[0] != d) {
                    ans.push_back(ans[0]);
                    ans.pop_front();
                }
                ans.push_front(c);
                bruh[c] = false;
            }
        }
    }

    vector<int> wut(0);
    for(int i = 0; i < ans.size(); i++) {
        wut.push_back(ans[i]);
    }
    if(ans.size() == n) {
        return wut;
    }
    else {
        if(ans.size() < n-ans.size()) {
            wut.clear();
            for(int i = 0; i < n; i++) {
                if(bruh[i]) {
                    wut.push_back(i);
                }
            }
        }
    }
    return wut;
}

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:69:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for(int i = 0; i < ans.size(); i++) {
      |                    ~~^~~~~~~~~~~~
longesttrip.cpp:72:19: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |     if(ans.size() == n) {
      |        ~~~~~~~~~~~^~~~
#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...