#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
struct DSU {
vector <int> par;
stack <int> stk;
int n;
inline void init(int _n) {
n = _n;
par.resize(n + 1);
}
int root(int x) {
if(par[x] == 0)
return x;
return par[x] = root(par[x]);
}
inline void join(int x, int y) {
x = root(x), y = root(y);
if(x != y) {
stk.push(x);
par[x] = y;
}
else {
stk.push(-1);
}
}
inline void undo() {
if(stk.top() != -1) {
par[stk.top()] = 0;
}
stk.pop();
}
};
const int MAXN = 100;
int A[MAXN + 1], B[MAXN + 1];
int a[MAXN + 1], b[MAXN + 1];
inline void add(int *arr, int &sz, vector <int> &cur) {
for(auto it : cur) {
arr[sz++] = it;
}
}
void run(int n) {
int i;
DSU dsu;
dsu.init(n);
for(int tt = 1; tt < n; tt++) {
vector < vector <int> > comp(n + 1);
vector <int> vis(n + 1, 0);
int sz = 0;
for(i = 1; i <= n; i++) {
int x = dsu.root(i);
if(!vis[x]) {
vis[x] = ++sz;
}
comp[vis[x] - 1].push_back(i);
}
/*for(i = 0; i < sz; i++) {
for(auto it : comp[i]) {
cerr << it << " ";
}
cerr << "\n";
}
cerr << "\n";*/
pair <int, int> cur;
int bit;
int sza, szb;
int sz1, sz0;
for(bit = 0; (1 << bit) < sz; bit++) {
sza = szb = 0;
sz1 = sz0 = 0;
for(i = 0; i < sz; i++) {
if(i & (1 << bit)) {
add(a, sza, comp[i]);
sz1++;
}
else {
add(b, szb, comp[i]);
sz0++;
}
}
if(query(sza, szb, a, b)) {
break;
}
}
int res = 0;
for(int step = 1 << 6; step; step >>= 1) {
if(res + step <= sz1) {
int cnt = res + step, sz = 0;
i = 0;
while(cnt > 0) {
if(i & (1 << bit)) {
cnt--;
add(A, sz, comp[i]);
}
i++;
}
if(!query(sz, szb, A, b)) {
res += step;
}
}
}
int cnt = res + 1;
for(i = 0; i < sz; i++) {
if(i & (1 << bit)) {
cnt--;
if(cnt == 0) {
cur.first = i;
break;
}
}
}
res = 0;
for(int step = 1 << 6; step; step >>= 1) {
if(res + step <= sz0) {
int cnt = res + step, sz = 0;
i = 0;
while(cnt > 0) {
if((i & (1 << bit)) == 0) {
cnt--;
add(B, sz, comp[i]);
}
i++;
}
if(!query(sza, sz, a, B)) {
res += step;
}
}
}
cnt = res + 1;
for(i = 0; i < sz; i++) {
if((i & (1 << bit)) == 0) {
cnt--;
if(cnt == 0) {
cur.second = i;
break;
}
}
}
//cerr << cur.first << " " << cur.second << "\n";
/*for(auto it : comp[0]) {
cerr << it << " ";
}
cerr << "\n";
for(auto it : comp[1]) {
cerr << it << " ";
}
cerr << "\n\n";*/
pair <int, int> edge;
res = -1;
sza = 0;
add(a, sza, comp[cur.first]);
for(int step = 1 << 6; step; step >>= 1) {
if(res + step < comp[cur.second].size()) {
int sz = 0;
for(i = 0; i <= res + step; i++) {
B[sz++] = comp[cur.second][i];
}
if(!query(sza, sz, a, B)) {
res += step;
}
}
}
edge.first = comp[cur.second][res + 1];
res = -1;
szb = 0;
add(b, szb, comp[cur.second]);
for(int step = 1 << 6; step; step >>= 1) {
if(res + step < comp[cur.first].size()) {
int sz = 0;
for(i = 0; i <= res + step; i++) {
A[sz++] = comp[cur.first][i];
}
if(!query(sz, szb, A, b)) {
res += step;
}
}
}
edge.second = comp[cur.first][res + 1];
dsu.join(edge.first, edge.second);
setRoad(edge.first, edge.second);
}
}
Compilation message
icc.cpp: In function 'void run(int)':
icc.cpp:164:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(res + step < comp[cur.second].size()) {
~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
icc.cpp:180:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(res + step < comp[cur.first].size()) {
~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
icc.cpp:106:26: warning: 'szb' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(!query(sz, szb, A, b)) {
~~~~~^~~~~~~~~~~~~~~
icc.cpp:134:26: warning: 'sza' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(!query(sza, sz, a, B)) {
~~~~~^~~~~~~~~~~~~~~
icc.cpp:124:13: warning: 'sz0' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(res + step <= sz0) {
^~
icc.cpp:96:13: warning: 'sz1' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(res + step <= sz1) {
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
476 KB |
Ok! 144 queries used. |
2 |
Correct |
10 ms |
504 KB |
Ok! 148 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
504 KB |
Ok! 774 queries used. |
2 |
Correct |
55 ms |
504 KB |
Ok! 791 queries used. |
3 |
Correct |
54 ms |
504 KB |
Ok! 833 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
632 KB |
Ok! 1981 queries used. |
2 |
Correct |
181 ms |
504 KB |
Ok! 1875 queries used. |
3 |
Correct |
170 ms |
568 KB |
Ok! 2146 queries used. |
4 |
Correct |
173 ms |
568 KB |
Ok! 2084 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
180 ms |
564 KB |
Too many queries! 2141 out of 2000 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
182 ms |
568 KB |
Too many queries! 2137 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
183 ms |
564 KB |
Too many queries! 2126 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |