#include<bits/stdc++.h>
#include "icc.h"
using namespace std;
#define pii pair<int, int>
const int MAX_N = 1e2;
int n;
vector<int> groups[MAX_N+1];
int dsu[MAX_N+1];
int my_query(int sa, int sb, int a[], int b[]){
for(int i = 0; i<sa; i++){
//cout<<a[i]<<" ";
}
//cout<<endl<<"__"<<endl;
for(int i = 0; i<sb; i++){
//cout<<b[i]<<" ";
}
//cout<<endl;
int res;
//cin>>res;
res = query(sa, sb, a, b);
return res;
}
void merge(int a, int b){
int ga = dsu[a];
int gb = dsu[b];
if(ga==gb){
return;
}
if(ga>gb){
swap(ga, gb);
}
for(auto e: groups[gb]){
groups[ga].push_back(e);
dsu[e] = ga;
}
groups[gb].clear();
}
void my_setRoad(int a, int b){
merge(a, b);
setRoad(a, b);
//cout<<"road "<<a<<" "<<b<<endl;
}
void pbv(vector<int>& a, vector<int>b){
a.insert(a.end(), b.begin(), b.end());
}
vector<int> all_except(int id){
vector<int> b;
for(int i = 0; i<n; i++){
if(i!=id){
pbv(b, groups[i]);
}
}
return b;
}
int query_group(int id){
vector<int> a;
pbv(a, groups[id]);
vector<int> b = all_except(id);
return my_query(a.size(), b.size(),&a[0], &b[0]);
}
void find(vector<int>& a, vector<int>& b){
int aid = -1;
for(int step = (1<<7); step>=1; step/=2){
if(aid+step<a.size()){
if(aid+step==0){
aid+=step;
continue;
}
//////cout<<"qa"<<endl;
if(my_query(a.size()-aid-step, b.size(), &a[aid+step], &b[0])){
aid+=step;
}
}
}
int bid= -1;
for(int step = (1<<7); step>=1; step/=2){
if(bid+step<b.size()){
if(bid+step==0){
bid+=step;
continue;
}
if(my_query(1, b.size()-bid-step, &a[aid], &b[bid+step])){
bid+=step;
}
}
}
//////cout<<aid<<" "<<bid<<endl;
my_setRoad(a[aid], b[bid]);
}
vector<int> get_ids_group(vector<int>& v){
vector<int> res;
for(auto e: v){
pbv(res, groups[e]);
}
return res;
}
struct Group{
vector<int> left;
vector<int> right;
void eq(){
if(right.size()>left.size()){
swap(left, right);
}
while(left.size()>right.size()){
right.push_back(left.back());
left.pop_back();
}
}
Group split(){
Group res;
res.left = left;
left.clear();
eq();
res.eq();
return res;
}
};
int has_link(Group A[], int sz){
vector<int> a;
vector<int> b;
for(int i = 0; i<sz; i++){
pbv(a, get_ids_group(A[i].left));
}
for(int i = 0; i<sz; i++){
pbv(b, get_ids_group(A[i].right));
}
return my_query(a.size(), b.size(), &a[0], &b[0]);
}
pair<vector<int>, vector<int>> get_split(){
vector<Group> f (1);
for(int i= 0; i<n; i++){
if(groups[i].size()>0){
f[0].left.push_back(i);
}
}
f[0].eq();
while(!has_link(&f[0], f.size())){
//cout<<"size "<<f.size()<<endl;
int s= f.size();
for(int i = 0; i<s; i++){
if(f[i].left.size() + f[i].right.size() >1){
f.push_back(f[i].split());
}
}
}
int cur= -1;
for(int step = (1<<7); step>=1; step/=2){
if(cur +step<f.size()){
if(cur+step+1==f.size()){
}
else if(!has_link(&f[0], cur+step+1)){
cur+=step;
}
}
}
cur++;
pair<vector<int>, vector<int>> res;
res.first= get_ids_group(f[cur].left);
res.second = get_ids_group(f[cur].right);
for(auto e: res.first){
//cout<<e<<" ";
}
//cout<<endl;
for(auto e: res.second){
//cout<<e<<" ";
}
//cout<<endl;
return res;
}
void run(int N){
srand(42);
n = N;
for(int i = 0; i<n; i++){
dsu[i+1] = i;
groups[i].push_back(i+1);
}
for(int i = 0; i<n-1; i++){
/*for(int i = 0; i<n; i++){
if(groups[i].size()>0){
if(query_group(i)==1){
auto tmp = all_except(i);
find(groups[i], tmp);
}
}
}*/
auto pvv = get_split();
//cout<<"ok"<<endl;
find(pvv.first, pvv.second);
}
}
Compilation message
icc.cpp: In function 'void find(std::vector<int>&, std::vector<int>&)':
icc.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | if(aid+step<a.size()){
| ~~~~~~~~^~~~~~~~~
icc.cpp:92:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | if(bid+step<b.size()){
| ~~~~~~~~^~~~~~~~~
icc.cpp: In function 'std::pair<std::vector<int>, std::vector<int> > get_split()':
icc.cpp:176:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Group>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
176 | if(cur +step<f.size()){
| ~~~~~~~~~^~~~~~~~~
icc.cpp:177:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Group>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
177 | if(cur+step+1==f.size()){
| ~~~~~~~~~~^~~~~~~~~~
icc.cpp:190:14: warning: unused variable 'e' [-Wunused-variable]
190 | for(auto e: res.first){
| ^
icc.cpp:194:14: warning: unused variable 'e' [-Wunused-variable]
194 | for(auto e: res.second){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Ok! 104 queries used. |
2 |
Correct |
4 ms |
468 KB |
Ok! 104 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
432 KB |
Ok! 531 queries used. |
2 |
Correct |
28 ms |
468 KB |
Ok! 521 queries used. |
3 |
Correct |
23 ms |
516 KB |
Ok! 552 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
500 KB |
Ok! 1396 queries used. |
2 |
Correct |
68 ms |
524 KB |
Ok! 1283 queries used. |
3 |
Correct |
75 ms |
520 KB |
Ok! 1541 queries used. |
4 |
Correct |
72 ms |
508 KB |
Ok! 1447 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
468 KB |
Ok! 1456 queries used. |
2 |
Correct |
75 ms |
508 KB |
Ok! 1458 queries used. |
3 |
Correct |
73 ms |
516 KB |
Ok! 1473 queries used. |
4 |
Correct |
70 ms |
500 KB |
Ok! 1425 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
512 KB |
Ok! 1455 queries used. |
2 |
Correct |
74 ms |
512 KB |
Ok! 1473 queries used. |
3 |
Correct |
73 ms |
504 KB |
Ok! 1465 queries used. |
4 |
Correct |
73 ms |
504 KB |
Ok! 1473 queries used. |
5 |
Correct |
70 ms |
508 KB |
Ok! 1434 queries used. |
6 |
Correct |
71 ms |
508 KB |
Ok! 1445 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
512 KB |
Ok! 1473 queries used. |
2 |
Correct |
74 ms |
504 KB |
Ok! 1452 queries used. |