# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1032306 | 0npata | Fun Tour (APIO20_fun) | C++17 | 21 ms | 504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fun.h"
#include<bits/stdc++.h>
using namespace std;
#define vec vector
const int MXN = 505;
vec<int> tree[MXN];
int depth[MXN];
void dfs1(int u, int p = -1) {
for(int v : tree[u]) {
if(v == p) continue;
depth[v] = depth[u]+1;
dfs1(v, u);
}
}
std::vector<int> createFunTour(int N, int Q) {
if(N>500) {
vec<int> ans(0);
for(int i = N-1; i>=0; i--) {
ans.push_back(i);
}
return ans;
}
for(int i = 0; i<N; i++) {
for(int j = 0; j<N; j++) {
if(i == j) {
continue;
}
if(hoursRequired(i, j) == 1) {
tree[i].push_back(j);
}
}
}
set<int> used;
auto comp_depth = [&](int u) {
depth[u] = 0;
dfs1(u);
};
comp_depth(0);
int x = 0;
for(int i = 0; i<N; i++) {
if(depth[i] > depth[x]) x = i;
}
vec<int> ans(0);
for(int i = 0; i<N; i++) {
comp_depth(x);
for(int i = 0; i<N; i++) {
if(!used.count(i) && depth[i] > depth[x]) x = i;
}
ans.push_back(x);
used.insert(x);
}
assert(used.size() == N);
return ans;
}
Compilation message (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... |