#include "meetings.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
vi sort_path(vi p, int start_path, int end_path)
{
if(siz(p) == 0)
{
return {start_path,end_path};
}
if(siz(p) == 1)
{
return {start_path,p[0],end_path};
}
int ind = los(0,siz(p)-1);
int v = p[ind];
vi p_left;
vi p_right;
forall(it,p)
{
if(it == v) continue;
int ans = Query(start_path,it,v);
if(ans == it) p_left.pb(it);
else p_right.pb(it);
}
// cout << " path\n";
vi v1 = sort_path(p_left,start_path,v);
vi v2 = sort_path(p_right,v,end_path);
rep2(i,1,siz(v2)-1) v1.pb(v2[i]);
return v1;
}
void solve(vi vert)
{
// forall(it,vert)
// {
// cout << it << " ";
// }
// cout << " verts\n";
if(siz(vert) <= 1) return;
int root = vert[los(0,siz(vert)-1)];
int end_path = vert[los(0,siz(vert)-1)];
while(root == end_path)
{
end_path = vert[los(0,siz(vert)-1)];
}
vi odp(siz(vert));
vi path = {};
unordered_map<int,int> mapa;
rep(i,siz(vert))
{
mapa[vert[i]] = i;
}
rep(i,siz(vert))
{
if(vert[i] != root && vert[i] != end_path)
{
int a = Query(root,end_path,vert[i]);
odp[i] = mapa[a];
if(a == vert[i])
{
path.pb(vert[i]);
}
}
else
{
// cout << i << " " << mapa[i] << " xd\n";
odp[i] = i;
}
}
// forall(it,path)
// {
// cout << it << " ";
// }
// cout << " path\n";
path = sort_path(path,root,end_path);
// forall(it,path)
// {
// cout << it << " ";
// }
// cout << " path\n";
rep(i,siz(path)-1)
{
// cout << path[i] << " " << path[i+1] << " edge\n";
Bridge(min(path[i],path[i+1]),max(path[i],path[i+1]));
}
vector<vi> group(siz(vert));
rep(i,siz(vert))
{
// cout << i << " " << odp[i] << " odp\n";
group[odp[i]].pb(vert[i]);
}
forall(it,group) solve(it);
}
void Solve(int n)
{
random_start();
vi vert;
rep(i,n) vert.pb(i);
solve(vert);
}
# | 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... |