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 ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXN = 2010;
mt19937_64 rng(69420);
ll random(ll l,ll r){
return rng()%(r-l+1)+l;
}
vector <ll> sub[MAXN];
ll lose[MAXN];
void dfs(ll u){
sort(sub[u].begin(),sub[u].end(),[](ll x,ll y){return lose[x]<lose[y];});
for (auto v:sub[u]){
if (lose[v] == lose[sub[u][0]]){
// cout<<"BR "<<u<<' '<<v<<endl;
Bridge(min(u,v),max(u,v));
dfs(v);
}
else break;
}
}
void solve(vector <ll> all){
if (sz(all)<2)return;
sort(all.begin(),all.end());
ll x = all[random(0,sz(all)-1)];
ll y = x;
while (y==x)y=all[random(0,sz(all)-1)];
map <ll,vector <ll> > mp;
for (auto z:all){
if (z!=x&&z!=y){
ll tmp = Query(x,y,z);
mp[tmp].push_back(z);
}
}
vector <ll> path;
path.push_back(x);
path.push_back(y);
for (auto z:mp)if (z.fi != x && z.fi != y){
path.push_back(z.fi);
}
stable_sort(path.begin(),path.end(),[&](ll a1,ll a2)->bool{
if (a1==x)return 1;
if (a2==x)return 0;
return Query(x,a1,a2)==a1;
});
for (ll j = 0;j + 1 < sz(path);j ++){
// cout<<path[j]<<' '<<path[j+1]<<'\n';
Bridge(min(path[j],path[j+1]),max(path[j],path[j+1]));
}
for (auto z:mp){
vector <ll> tmp = z.se;
tmp.push_back(z.fi);
sort(tmp.begin(),tmp.end());
tmp.resize(unique(tmp.begin(),tmp.end())-tmp.begin());
solve(tmp);
}
}
void Solve(int n) {
vector <ll> all(n);
iota(all.begin(),all.end(),0);
solve(all);
}
# | 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... |