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"
#pragma once
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
map<pair<int,int>,int> asked;
int lvl[2005];
int my_query(int u,int v,int w){
u--;
v--;
w--;
if(v == w){
return v + 1;
}
if(v > w){
swap(v,w);
}
// printf("%d %d %d\n",u,v,w);
if(asked.count({v,w}) == 0){
asked[{v,w}] = Query(u,v,w);
}
if(lvl[asked[{v,w}] + 1] < lvl[u + 1]){
return u + 1;
}
return asked[{v,w}] + 1;
}
void my_bridge(int u,int v){
u--;
v--;
if(u > v){
swap(u,v);
}
// printf("%d %d\n",u,v);
Bridge(u,v);
}
void solve(int root,vector<int> &nodes){
for(int i = 0;i < (int)nodes.size();i++){
if(nodes[i] == root){
swap(nodes[i],nodes.back());
nodes.pop_back();
break;
}
}
if(nodes.size() == 0){
return;
}
if(nodes.size() == 1){
my_bridge(root,nodes[0]);
return ;
}
vector<pair<pair<int,int>,vector<int> > > sons;sons.clear();
for(auto it:nodes){
random_shuffle(sons.begin(),sons.end());
bool ins = false;
for(int i = 0;i < (int)sons.size();i++){
int tmp = my_query(root,sons[i].first.second,it);
if(tmp != root){
sons[i].first.second = tmp;
sons[i].first.first++;
sons[i].second.push_back(it);
ins = true;
break;
}
}
if(ins == false){
sons.push_back({{1,it},{it}});
}
}
for(int i = 0;i < (int)sons.size();i++){
my_bridge(root,sons[i].first.second);
lvl[sons[i].first.second] = 1 + lvl[root];
}
for(int i = 0;i < (int)sons.size();i++){
solve(sons[i].first.second,sons[i].second);
}
}
void Solve(int N) {
vector<int> nodes;
for(int i = 1;i <= N;i++){
nodes.push_back(i);
}
solve(1,nodes);
}
Compilation message (stderr)
meetings.cpp:2:9: warning: #pragma once in main file
#pragma once
^~~~
# | 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... |