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;
using vi = vector<int>;
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)2e3+9;
int n, vis[mxN];
vi v[mxN];
void mergeSort(vi &v, int a, int b){
if(sz(v)<=1) return;
int mid = sz(v)/2;
vi w,x; w.clear(), x.clear();
for(int i = 0; i < mid; i++) w.pb(v[i]);
for(int i = mid; i < sz(v); i++) x.pb(v[i]);
mergeSort(w,a,b), mergeSort(x,a,b); v.clear();
int i = 0, j = 0;
while(i<sz(w) and j<sz(x)){
if(Query(a,w[i],x[j])==w[i]) v.pb(w[i++]);
else v.pb(x[j++]);
}
while(i<sz(w)) v.pb(w[i++]);
while(j<sz(x)) v.pb(x[j++]);
}
void bridge(int a, int b){ return Bridge(min(a,b),max(a,b)); }
void recur(int a, vi &w){
if(sz(w)<1) return;
int b = w[rand()%sz(w)]; vis[a]=vis[b]=1;
vi path, v[n+1]; path.clear();
for(auto i : w){ if(!vis[i]){
int x = Query(a,b,i);
if(x==i) path.pb(i),vis[i]=1;
else v[x].pb(i);
} }
mergeSort(path,a,b);
if(path.empty()) bridge(a,b);
else bridge(a,path[0]),bridge(path.back(),b);
for(int i = 0; i < sz(path)-1; i++) bridge(path[i],path[i+1]);
for(auto u : path) recur(u,v[u]);
recur(a,v[a]), recur(b,v[b]);
}
void Solve(int N) {
n = N; int x = rand()%N;
for(int i = 0; i < n; i++) if(x!=i) v[x].pb(i);
random_shuffle(begin(v[x]),end(v[x])); recur(x,v[x]);
}
# | 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... |