제출 #1073258

#제출 시각아이디문제언어결과실행 시간메모리
1073258Unforgettablepl가장 긴 여행 (IOI23_longesttrip)C++17
25 / 100
909 ms1404 KiB
#pragma GCC optimize("Ofast","unroll-all-loops")
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> longest_trip(int N,int D){
    vector<vector<int>> adj(N);
    for(int i=0;i<N;i++) {
        for(int j=i+1;j<N;j++) {
            if(are_connected({i},{j})) {
                adj[i].emplace_back(j);
                adj[j].emplace_back(i);
            }
        }
    }
    int ans = 0;
    int lim = N/2 + (N&1);
    for(int i=0;i<N;i++) {
        vector<bool> visited(N);
        function<void(int,int)> dfs = [&](int x,int depth) {
            visited[x]=true;
            ans=max(ans,depth);
            for(int&v:adj[x])if(!visited[v])dfs(v,depth+1);
        };
        dfs(i,0);
        if(ans>=lim)break;
    }
    vector<int> full;
    ans = min(ans,lim);
    for(int i=0;i<N;i++) {
        stack<int> path;
        vector<bool> visited(N);
        function<void(int,int)> dfs = [&](int x,int depth) {
            visited[x]=true;
            path.emplace(x);
            if(ans==depth) {
                while(!path.empty()) {
                    full.emplace_back(path.top());
                    path.pop();
                }
            }
            for(int&v:adj[x])if(!visited[v]) {
                dfs(v,depth+1);
                if(!full.empty())return;
            }
            path.pop();
        };
        dfs(i,0);
        if(!full.empty())return full;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:7:30: warning: control reaches end of non-void function [-Wreturn-type]
    7 |     vector<vector<int>> adj(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...