제출 #1131488

#제출 시각아이디문제언어결과실행 시간메모리
1131488boris_mihovFun Tour (APIO20_fun)C++17
26 / 100
73 ms15944 KiB
#include "fun.h" #include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <vector> typedef long long llong; const int MAXN = 100000 + 10; const int INF = 1e9; int n, q; bool active[MAXN]; std::vector <int> g[MAXN]; std::pair <int,int> find_furthest(int node, int par) { std::pair <int,int> ans = {0, -INF}; if (active[node]) { ans = {node, 0}; } for (const int u : g[node]) { if (u == par) { continue; } auto [v, d] = find_furthest(u, node); if (d >= ans.second) { ans = {v, d + 1}; } } return ans; } std::vector <int> createFunTour(int N, int Q) { n = N; q = Q; for (int i = 1 ; i <= n ; ++i) { active[i] = true; } for (int i = 1 ; i <= n ; ++i) { for (int j = i + 1 ; j <= n ; ++j) { if (hoursRequired(i - 1, j - 1) == 1) { g[i].push_back(j); g[j].push_back(i); } } } std::vector <int> sol; int root = find_furthest(1, 0).first; for (int i = 1 ; i <= n ; ++i) { active[root] = false; sol.push_back(root - 1); root = find_furthest(root, 0).first; } return sol; }
#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...