이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
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);
}
vector<int> full;
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:6:30: warning: control reaches end of non-void function [-Wreturn-type]
6 | vector<vector<int>> adj(N);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |