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>
#define PB push_back
#define sz(x) ((int)x.size())
#define i2 array<int,2>
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 100100;
vector<int> g[N], ans, vc[2];
int siz[N], glob, mx;
bool mrk[N];
void dfs(int v, int p, int len){
if (mx < len){
mx = len;
glob = v;
}
for (int u : g[v]){
if (u == p || mrk[u]) continue;
dfs(u, v, len + 1);
}
}
int get(int v, int tp){
for (int it = sz(g[v]) - 1; it >= 0; it--){
int u = g[v][it];
if (mrk[u]) continue;
get(u, tp);
}
vc[tp].PB(v);
}
vector<int> createFunTour(int n, int Q) {
if (n <= 500){
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++){
int now = hoursRequired(i, j);
if (now == 1){
g[i].PB(j);
g[j].PB(i);
}
}
} else
{
for (int i = 1; i < n; i++){
int j = (i - 1) / 2;
// g[i].PB(j);
g[j].PB(i);
}
int rem = n, root = 0;
while (rem > 0){
vc[0].clear();
vc[1].clear();
get(g[root][0], 0);
get(g[root][1], 1);
for (int i = 0; i < sz(vc[1]); i++){
ans.PB(vc[0][i]);
ans.PB(vc[1][i]);
mrk[vc[0][i]] = 1;
mrk[vc[1][i]] = 1;
rem -= 2;
}
if (sz(vc[0]) == sz(vc[1])){
rem--;
assert(rem == 0);
ans.PB(root);
break;
} else {
rem -= 2;
ans.PB(vc[0][sz(vc[1])]);
ans.PB(root);
mrk[vc[0][sz(vc[1])]] = 1;
mrk[root] = 1;
}
if (rem == 0) break;
root = g[root][0];
assert(!mrk[root]);
}
return ans;
}
ans.clear();
mx = -1;
dfs(0, -1, 0);
for (int it = 0; it < n; it++){
ans.PB(glob);
mrk[glob] = 1;
mx = -1;
dfs(glob, -1, 0);
}
return ans;
}
Compilation message (stderr)
fun.cpp: In function 'int get(int, int)':
fun.cpp:36:1: warning: no return statement in function returning non-void [-Wreturn-type]
36 | }
| ^
# | 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... |