| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1056731 | mc061 | 가장 긴 여행 (IOI23_longesttrip) | C++17 | 10 ms | 904 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> path;
vector<int> mxpath;
int n;
set<int> have;
const int maxN = 256;
bool connected[maxN][maxN]={};
bool ans[maxN][maxN]={};
bool vis[maxN]={};
set<int> comp;
bool are_connected(vector<int> A, vector<int> B);
void dfs(int v, bool fill_comp = false) {
path.push_back(v);
have.insert(v);
vis[v] = true;
if (fill_comp) comp.insert(v);
if (path.size() == n) {
return;
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
random_shuffle(ord.begin(), ord.end());
for (int i : ord) {
if (!have.count(i)) {
bool c = false;
if (ans[v][i]) {
c = connected[v][i];
}
else {
ans[v][i] = ans[i][v] = true;
bool x = are_connected(vector<int>{i}, vector<int>{v});
connected[v][i] = connected[i][v] = x;
c = x;
}
if (c)
dfs(i);
}
if (path.size() == n) return;
}
if (path.size() == n) return;
if (path.size() > mxpath.size()) {
mxpath = path;
}
path.pop_back();
have.erase(v);
}
vector<int> longest_trip(int N, int D) {
memset(connected, 0, sizeof(connected));
memset(ans, 0, sizeof(ans));
n = N;
int start = 0;
comp.clear();
memset(vis, 0, sizeof(vis));
path.clear();
have.clear();
dfs(0, true);
int cnt = comp.size();
if (cnt == n) {
return mxpath.size() > path.size() ? mxpath : path;
}
for (int i = 0; i < n; ++i) {
if (!vis[i]) {
dfs(i);
break;
}
}
return mxpath.size() > path.size() ? mxpath : path;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
