이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> createFunTour(int n, int q) {
//int h = hoursRequired(0, n - 1);
//int a = attractionsBehind(0, n - 1);
vector<vector<int>> g(n);
int cnt_edges = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (hoursRequired(i, j) == 1) {
g[i].push_back(j);
g[j].push_back(i);
cnt_edges++;
}
}
}
assert(cnt_edges == n - 1);
vector<bool> active(n, 1);
vector<int> dist(n, -1);
function<int(int)> find_far = [&] (int root) {
assert(active[root]);
queue<int> q;
for (int i = 0; i < n; i++) {
dist[i] = -1;
}
dist[root] = 0;
q.push(root);
while (!q.empty()) {
int a = q.front();
q.pop();
for (auto &b : g[a]) {
if (active[b] && dist[b] == -1) {
dist[b] = 1 + dist[a];
q.push(b);
}
}
}
int sol = root;
for (int i = 0; i < n; i++) {
if (dist[i] > dist[sol]) {
sol = i;
}
}
return sol;
};
vector<int> ord;
ord.push_back(find_far(0));
for (int step = 2; step <= n; step++) {
int nw = find_far(ord.back());
active[ord.back()] = 0;
ord.push_back(nw);
}
assert((int) ord.size() == n);
return ord;
///return std::vector<int>(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... |