Submission #657292

#TimeUsernameProblemLanguageResultExecution timeMemory
657292600MihneaFun Tour (APIO20_fun)C++17
26 / 100
14 ms388 KiB
#include "fun.h" #include <bits/stdc++.h> using namespace std; vector<int> createFunTourForSubtasks1and2(int n, int q) { 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; } vector<int> createFunTour(int n, int q) { if (n <= 500) { return createFunTourForSubtasks1and2(n, q); } return {}; }
#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...