Submission #657290

#TimeUsernameProblemLanguageResultExecution timeMemory
657290600MihneaFun Tour (APIO20_fun)C++17
26 / 100
97 ms16724 KiB
#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 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...