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 "meetings.h"
#include <bits/stdc++.h>
using namespace std;
void solve(vector<int> v){
/*printf("solving ");
for (auto x : v) printf("%d ",x);
printf("\n");*/
if (v.size() == 1) return;
if (v.size() == 2){
if (v[0] > v[1]) swap(v[0],v[1]);
Bridge(v[0],v[1]);
return;
}
random_shuffle(v.begin(),v.end());
int p = v[0], q = v[1];
//printf("cur %d, root %d\n",cur,root);
for (auto x : v){
if (x == p || x == q) continue;
int Q = Query(p,q,x);
if (Q != p) q = Q;
}
//printf("cur %d, root %d\n",cur,root);
if (p > q) swap(p,q);
Bridge(p,q);
vector<int> L, R;
for (auto x : v){
if (x == q || x == p) continue;
int Q = Query(p,q,x);
assert(Q == p || Q == q);
if (Q == p) R.push_back(x);
else L.push_back(x);
}
L.push_back(q);
R.push_back(p);
solve(L);
solve(R);
}
void Solve(int N) {
vector<int> cur;
for (int i = 0; i < N; i++) cur.push_back(i);
solve(cur);
}
# | 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... |