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 "grader.cpp"
////////////////////////////////
#include <bits/stdc++.h>
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define pii pair<int, int>
using namespace std;
const int MAXN = (int)1e5 + 5;
const int MAXQ = (int)4e5 + 5;
vector <int> g[MAXN];
bool used[MAXN];
int dist[MAXN];
int n;
void calc(int v, int par, int len) {
dist[v] = len;
for (int to : g[v]) {
if (to == par) {
continue;
}
calc(to, v, len + 1);
}
}
int get_max() {
int pos = -1, mx = 0;
for (int i = 0; i < n; i++) {
if (!used[i] && dist[i] > mx) {
mx = dist[i];
pos = i;
}
}
return pos;
}
vector <int> createFunTour(int N, int Q) {
n = N;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (hoursRequired(i, j) == 1) {
g[i].pb(j);
g[j].pb(i);
}
}
}
int a = 1;
calc(a, -1, 0);
int b = get_max();
calc(b, -1, 0);
int c = get_max();
vector <int> ans = {b, c};
used[b] = used[c] = 1;
int used_cnt = 2;
int last = c;
while (used_cnt < n) {
calc(last, -1, 0);
int nxt = get_max();
ans.pb(nxt);
used[nxt] = 1;
used_cnt++;
}
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... |