# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
123962 | sebinkim | Meetings (JOI19_meetings) | C++14 | 0 ms | 0 KiB |
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;
typedef pair <int, int> pii;
void f(int p, vector <int> &V)
{
vector <int> X;
vector <pii> Y;
int i, j, v, q;
swap(V[rand() % V.size()], V.back());
q = V.back(); V.pop_back();
for(int &t: V){
v = Query(p, q, t);
if(t == v) X.push_back(t);
else Y.emplace_back(v, t);
}
if(X.empty()) Bridge(p, q);
else{
sort(X.begin(), X.end(), [&](int &a, int &b){
if(a == b) return 0;
return Query(p, a, b) == a;
});
Bridge(p, X[0]);
for(i=1; i<X.size(); i++){
Bridge(X[i - 1], X[i]);
}
Bridge(X.back(), q);
}
sort(Y.begin(), Y.end());
for(i=0; i<Y.size(); i=j){
V.clear();
for(j=i; j<Y.size() && Y[j].first == Y[i].first; j++){
V.push_back(Y[j].second);
}
f(Y[i].first, V);
}
}
void Solve(int n)
{
vector <int> V;
int i;
srand(time(0));
for(i=1; i<n; i++){
V.push_back(i);
}
f(0, V);
}