This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
vector<int> ans;
int i, j;
vector<int> adj[505];
bool checked[505];
pair<int, int> findFar(int x, int p=-1, int dist=0) {
pair<int, int> mxDist = make_pair(0, -1);
if (!checked[x]) mxDist = make_pair(dist, x);
for (auto y : adj[x]) {
if (y == p) continue;
mxDist = max(mxDist, findFar(y, x, dist+1));
}
return mxDist;
}
vector<int> createFunTour(int n, int q) {
for (i=0; i < n; ++i) {
for (j=0; j < n; ++j) {
if (i == j) continue;
if (hoursRequired(i,j) == 1) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
fill(checked, checked+n, false);
ans.push_back(findFar(0).Y);
checked[ans[0]] = true;
for (i=1; i < n; ++i) {
ans.push_back(findFar(ans[i-1]).Y);
checked[ans[i]] = true;
}
return ans;
}
# | 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... |