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<bits/stdc++.h>
#include "meetings.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );
void bridge(int u, int v) { Bridge(min(u, v), max(u, v) ); }
vector<vector<int> > rem;
void solve(int l) {
if (!sz(rem[l]) ) return ;
int r = rem[l].back(); rem[l].pop_back();
vector<int> tmp = rem[l];
rem[l].clear(); rem[r].clear();
for (int u : tmp) rem[u].clear();
vector<int> path;
for (auto u : tmp) {
int pr = Query(l, r, u);
if (pr == u) {
if (u != l && u != r) path.emplace_back(u);
}
else rem[pr].emplace_back(u);
}
if (sz(path) ) {
sort(all(path), [&](int u, int v) { return Query(l, u, v) == u; });
bridge(l, path[0]);
bridge(r, path.back() );
for (int i = 0; i + 1 < sz(path); ++i) bridge(path[i], path[i + 1]);
}
else bridge(l, r);
solve(l); solve(r);
for (auto &u : path) solve(u);
}
void Solve(int N) {
rem.assign(N, {} );
for (int u = 1; u < N; ++u) rem[0].emplace_back(u);
solve(0);
}
# | 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... |