#include "icc.h"
#include <iostream>
#include <vector>
using namespace std;
int p[105], s[105];
vector<int> v[105];
int Find(int x) {
if (x == p[x]) return x;
return p[x] = Find(p[x]);
}
void Merge(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y) return;
if (s[x] < s[y]) swap(x, y);
s[x] += s[y];
p[y] = x;
}
/*int query(int n, int m, int a[], int b[]) {
cout << n << " " << m << endl;
for (int i = 0; i < n; i++) cout << a[i] << " ";
cout << endl;
for (int i = 0; i < m; i++) cout << b[i] << " ";
cout << endl;
int k;
cin >> k;
return k;
}*/
int query(vector<int> a, vector<int> b) {
int c[a.size()], d[b.size()];
for (int i = 0; i < a.size(); i++) c[i] = a[i];
for (int i = 0; i < b.size(); i++) d[i] = b[i];
return query(a.size(), b.size(), c, d);
}
void run(int n) {
for (int i = 1; i <= n; i++) {
p[i] = i;
s[i] = 1;
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= n; j++) {
v[j].clear();
}
for (int j = 1; j <= n; j++) {
int h = Find(j);
v[h].push_back(j);
}
vector<int> vv, va, vb;
for (int j = 1; j <= n; j++) {
if (!v[j].empty()) {
vv.push_back(j);
}
}
for (int j = 0; j < 7; j++) {
vector<int> a, b;
for (int i = 0; i < vv.size(); i++) {
int w = vv[i];
if (i & (1 << j)) {
for (int ww : v[w]) a.push_back(ww);
}
else {
for (int ww : v[w]) b.push_back(ww);
}
}
if (query(a, b)) {
va = a;
vb = b;
break;
}
}
int l = 0, r = va.size() - 1, res;
while (l != r) {
int mid = (l + r) / 2;
vector<int> vc;
for (int i = l; i <= mid; i++) {
vc.push_back(va[i]);
}
if (query(vc, vb)) {
r = mid;
}
else l = mid + 1;
}
res = l;
l = 0; r = vb.size() - 1;
while (l != r) {
int mid = (l + r) / 2;
vector<int> vc;
for (int i = l; i <= mid; i++) {
vc.push_back(vb[i]);
}
if (query(va, vc)) {
r = mid;
}
else l = mid + 1;
}
setRoad(va[res], vb[l]);
Merge(va[res], vb[l]);
}
}
/*int main() {
run(4);
}*/
Compilation message
icc.cpp: In function 'int query(std::vector<int>, std::vector<int>)':
icc.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < a.size(); i++) c[i] = a[i];
| ~~^~~~~~~~~~
icc.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i = 0; i < b.size(); i++) d[i] = b[i];
| ~~^~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:56:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 0; i < vv.size(); i++) {
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Ok! 99 queries used. |
2 |
Correct |
4 ms |
604 KB |
Ok! 98 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
604 KB |
Ok! 535 queries used. |
2 |
Correct |
25 ms |
600 KB |
Ok! 659 queries used. |
3 |
Correct |
24 ms |
604 KB |
Ok! 658 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
636 KB |
Ok! 1424 queries used. |
2 |
Correct |
72 ms |
632 KB |
Ok! 1612 queries used. |
3 |
Correct |
75 ms |
604 KB |
Ok! 1655 queries used. |
4 |
Correct |
70 ms |
856 KB |
Ok! 1504 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
620 KB |
Ok! 1596 queries used. |
2 |
Correct |
69 ms |
616 KB |
Ok! 1472 queries used. |
3 |
Correct |
78 ms |
600 KB |
Ok! 1636 queries used. |
4 |
Correct |
70 ms |
600 KB |
Ok! 1519 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
620 KB |
Ok! 1629 queries used. |
2 |
Correct |
83 ms |
600 KB |
Ok! 1611 queries used. |
3 |
Correct |
75 ms |
600 KB |
Ok! 1646 queries used. |
4 |
Correct |
75 ms |
628 KB |
Ok! 1653 queries used. |
5 |
Correct |
80 ms |
624 KB |
Ok! 1486 queries used. |
6 |
Correct |
74 ms |
604 KB |
Ok! 1555 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
76 ms |
620 KB |
Too many queries! 1635 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |