#include "fun.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int MAXN = 505;
vector<int> con[MAXN];
bool used[MAXN];
pair<int, int> find_depth(int curr, int par){ // depth, node
pair<int, int> res = {-1, -1};
for (auto i : con[curr]){
if (i == par or used[i]) continue;
pair<int, int> b = find_depth(i, curr);
if (b.first > res.first) res = b;
}
if (res.first == -1)
return {1, curr};
return {res.first + 1, res.second};
}
int find_remove(int start){ // node
pair<int, int> best ={-1, -1};
for (auto i : con[start]){
if (used[i]) continue;
pair<int, int> res = find_depth(i, start);
if (best.second == -1 or (best.second != res.second and best.first < res.first))
best = res;
}
return best.second;
}
void make_tree(int n){
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (hoursRequired(i, j) == 1)
con[i].push_back(j), con[j].push_back(i);
}
std::vector<int> createFunTour(int n, int Q) {
vector<int> res;
make_tree(n);
for (int start = 0; start < n; start++){
int total = n;
for (int i = 0; i < n; i++) used[i] = false;
res.clear();
while (total > 1){
if (used[start])
break;
int t = find_remove(start);
total--;
used[t] = true;
res.push_back(t);
}
if (!used[start]) break;
}
for (int i = 0; i < n; i++)
if (!used[i]) res.push_back(i);
return res;
}
# | 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... |