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>
#define pb push_back
using namespace std;
const int maxn = 2e3 + 4;
int L[maxn][maxn];
int LCA(int u , int v){
if(u == 0 || v == 0)return 0;
if(u == v)return u;
if(u > v)swap(u , v);
if(L[u][v] != -1)return L[u][v];
return L[u][v] = Query(0 , u , v);
}
void Solve(int root , vector<int> child){
// for(int c : child)cout << c << " ";cout << endl;
if((int)child.size() <= 1)return;
map<int,vector<int>> mmap;
int u = child[rand() % child.size()];
while(u == root)u = child[rand() % child.size()];
vector<int> can;
for(int c : child){
int a = LCA(c , u);
if(a == c)
can.pb(c);
mmap[a].pb(c);
}
sort(can.begin(),can.end(),[&](const int & x , const int & y){
return LCA(x , y) == x;
});
for(int i = 0 ; i < (int)can.size() - 1 ; ++i){
Bridge(min(can[i] , can[i + 1]) , max(can[i] , can[i + 1]));
}
for(auto& c : mmap)Solve(c.first , c.second);
}
void Solve(int n) {
srand(time(0));
memset(L,-1,sizeof L);
vector<int> v(n);
for(int i = 0 ; i < n ; ++i)v[i] = i;
Solve(0 , v);
}
# | 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... |