Submission #1072719

#TimeUsernameProblemLanguageResultExecution timeMemory
1072719thinknoexitFun Tour (APIO20_fun)C++17
26 / 100
1222 ms524288 KiB
#include "fun.h" #include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 100100; int n; vector<int> adj[N]; vector<int> res; int deg[N]; bool ch[N]; void dfs(int v, vector<int>& node, int p = -1) { node.push_back(v); for (auto& x : adj[v]) { if (x == p || ch[x]) continue; dfs(x, node, v); } } void dnc(int v) { vector<int> l, r; bool __ = 0; for (auto& x : adj[v]) { if (ch[x]) continue; if (!__) dfs(x, l, v), __ = 1; else dfs(x, r, v); } sort(l.rbegin(), l.rend()), sort(r.rbegin(), r.rend()); int sz = r.size(); for (int i = 0;i < sz;i++) { res.push_back(l[i]); res.push_back(r[i]); } res.push_back(v); if (l.size() == r.size()) return; dnc(l.back()); } vector<int> createFunTour(int _N, int Q) { n = _N; if (n <= 500) { vector<bool> ch(n, false); vector<vector<int>> dis(n, vector<int>(n, 0)); for (int i = 0;i < n;i++) { for (int j = i + 1;j < n;j++) { dis[i][j] = dis[j][i] = hoursRequired(i, j); } } int mx = 0, idx = 0; for (int i = 0;i < n;i++) { if (dis[0][i] > mx) { mx = dis[0][i]; idx = i; } } vector<int> res; res.push_back(idx); ch[idx] = 1; for (int i = 1;i < n;i++) { int mx = 0, idx = 0; for (int j = 0;j < n;j++) { if (ch[j]) continue; if (dis[res.back()][j] > mx) { mx = dis[res.back()][j]; idx = j; } } ch[idx] = 1; res.push_back(idx); } return res; } for (int i = 1;i < n;i++) { adj[i].push_back((i - 1) / 2); adj[(i - 1) / 2].push_back(i); } dnc(0); }

Compilation message (stderr)

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:74:8: warning: control reaches end of non-void function [-Wreturn-type]
   74 |     dnc(0);
      |     ~~~^~~
#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...