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, int root){
//printf("solving ");
//for (auto x : v) printf("%d ",x);
//printf(", %d\n",root);
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 cur = v[0] == root ? v[1] : v[0];
//printf("cur %d, root %d\n",cur,root);
for (auto x : v){
if (x == cur || x == root ) continue;
int Q = Query(root,cur,x);
if (Q != root) cur = Q;
}
//printf("cur %d, root %d\n",cur,root);
if (cur > root) swap(cur,root);
Bridge(cur,root);
vector<int> L, R;
for (auto x : v){
if (x == cur || x == root) continue;
int Q = Query(root,cur,x);
assert(Q == root || Q == cur);
if (Q == root) R.push_back(x);
else L.push_back(x);
}
L.push_back(cur);
R.push_back(root);
solve(L,cur);
solve(R,root);
}
void Solve(int N) {
vector<int> cur;
for (int i = 0; i < N; i++) cur.push_back(i);
solve(cur,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... |