#include<bits/stdc++.h>
#include "icc.h"
using namespace std;
#define endl "\n"
const int N = 100;
int a[N + 1],b[N + 1],pa[N + 1],n;
vector<int> st[N + 1];
int find(int a) {
if(a == pa[a]) return a;
return pa[a] = find(pa[a]);
}
void unite(int a,int b) {
a = find(a);
b = find(b);
if(a == b) return;
if(st[a].size() < st[b].size()) swap(a,b);
pa[b] = a;
for(auto u : st[b]) {
st[a].push_back(u);
}
}
int ask(vector<int> i1,vector<int> i2) {
vector<int> l,r;
for(auto u : i1) {
for(auto v : st[u]) {
l.push_back(v);
}
}
for(auto u : i2) {
for(auto v : st[u]) {
r.push_back(v);
}
}
for(int i = 0;i < l.size();i++) {
a[i] = l[i];
}
for(int i = 0;i < r.size();i++) {
b[i] = r[i];
}
return query((int)l.size(),(int)r.size(),a,b);
}
pair<int,int> cal(vector<int> le,vector<int> ri) {
int l = 0,r = le.size(),trai = -1,phai = -1;
vector<int> tmp;
while(l < r) {
int mid = (l + r)/2;
tmp.clear();
for(int i = l;i <= mid;i++) {
tmp.push_back(le[i]);
}
if(ask(tmp,ri)) {
trai = mid;
r = mid;
} else {
l = mid + 1;
}
}
l = 0;
r = ri.size();
while(l < r) {
int mid = (l + r)/2;
tmp.clear();
for(int i = l;i <= mid;i++) {
tmp.push_back(ri[i]);
}
if(ask(le,tmp)) {
phai = mid;
r = mid;
} else {
l = mid + 1;
}
}
return {le[trai],ri[phai]};
}
void process() {
vector<int> tl,tr;
for(int pos = 0;pos < 7;pos++) {
tl.clear();
tr.clear();
for(int i = 1;i <= n;i++) {
if(i != find(i)) continue;
if((i >> pos) % 2 == 0) {
tl.push_back(i);
} else {
tr.push_back(i);
}
}
if(ask(tl,tr)) {
vector<int> i1,i2;
for(auto u : tl) {
for(auto v : st[u]) {
i1.push_back(v);
}
}
for(auto u : tr) {
for(auto v : st[u]) {
i2.push_back(v);
}
}
auto res = cal(i1,i2);
setRoad(res.first,res.second);
unite(res.first,res.second);
break;
}
}
}
void run(int N) {
n = N;
for(int i = 1;i <= n;i++) {
pa[i] = i;
st[i].push_back(i);
}
for(int i = 1;i < n;i++) {
process();
}
}
Compilation message
icc.cpp: In function 'int ask(std::vector<int>, std::vector<int>)':
icc.cpp:43:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i = 0;i < l.size();i++) {
| ~~^~~~~~~~~~
icc.cpp:46:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0;i < r.size();i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
504 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
596 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |