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;
mt19937 rng(time(0));
int K;
bool cmp(int a,int b){
return Query(K,a,b)==a;
}
void qq(int a,int b){
if(a>b)swap(a,b);
Bridge(a,b);
}
void go(int k,vector<int>temp){
if(temp.size()==0)return;
int n=temp.size();
int k2=rng()%n;
K=k;
vector<int>child[n],path;
for(auto i:temp){
int p=Query(k,k2,i);
if(p==i){
path.push_back(i);
}
else{
child[p].push_back(i);
}
}
sort(path.begin(),path.end(),cmp);
for(int i=0;i<n;i++){
if(!i){
qq(k,path[i]);
}
else{
qq(path[i-1],path[i]);
}
}
go(k,child[k]);
for(auto i:path){
go(i,child[i]);
}
}
void Solve(int N){
int n=N;
int k=rng()%n;
vector<int>temp;
for(int i=0;i<n;i++){
if(i!=k)temp.push_back(i);
}
go(k,temp);
}
/*
input:
*/
# | 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... |