#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
const int N = 105;
int qa[N], qb[N];
int query(vector<int> a, vector<int> b) {
int sza = a.size(), szb = b.size();
for (int i = 0; i < sza; ++i) {
qa[i] = a[i];
}
for (int i = 0; i < szb; ++i) {
qb[i] = b[i];
}
return query(sza, szb, qa, qb);
}
int fnd(vector<int> from, vector<int> to) {
int l = 0, r = from.size() - 1;
while (l < r) {
int md = (l + r) >> 1;
if (query(vector<int>(from.begin(), from.begin() + md + 1), to)) {
r = md;
} else {
l = md + 1;
}
}
return from[l];
}
int p[N];
vector<int> comp[N];
int getp(int u) {
if (p[u] == u) {
return u;
} else {
return p[u] = getp(p[u]);
}
}
void mrg(int u, int v) {
u = getp(u), v = getp(v);
if (comp[u].size() < comp[v].size()) {
swap(u, v);
}
p[v] = u;
for (int w : comp[v]) {
comp[u].push_back(w);
}
}
void modify(vector<int> l, vector<int> r) {
int u = fnd(l, r);
int v = fnd(r, l);
mrg(u, v);
setRoad(u, v);
}
int n;
void solve() {
vector<int> roots;
for (int i = 1; i <= n; ++i) {
if (p[i] == i) {
roots.push_back(i);
}
}
shuffle(roots.begin(), roots.end(), mt19937(10072002));
int sz = roots.size();
for (int i = 0; (1 << i) < sz; ++i) {
vector<int> l, r;
for (int j = 0; j < sz; ++j) {
if (j & (1 << i)) {
for (int v : comp[roots[j]]) {
l.push_back(v);
}
} else {
for (int v : comp[roots[j]]) {
r.push_back(v);
}
}
}
if (query(l, r)) {
modify(l, r);
return;
}
}
}
void run(int n) {
::n = n;
for (int i = 1; i <= n; ++i) {
p[i] = i;
comp[i].push_back(i);
}
for (int i = 0; i < n - 1; ++i) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
512 KB |
Ok! 100 queries used. |
2 |
Correct |
8 ms |
512 KB |
Ok! 100 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
512 KB |
Ok! 533 queries used. |
2 |
Correct |
42 ms |
512 KB |
Ok! 652 queries used. |
3 |
Correct |
42 ms |
640 KB |
Ok! 644 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
512 KB |
Ok! 1379 queries used. |
2 |
Correct |
139 ms |
604 KB |
Ok! 1610 queries used. |
3 |
Correct |
129 ms |
632 KB |
Ok! 1598 queries used. |
4 |
Correct |
129 ms |
564 KB |
Ok! 1503 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
512 KB |
Ok! 1508 queries used. |
2 |
Correct |
134 ms |
512 KB |
Ok! 1452 queries used. |
3 |
Correct |
133 ms |
512 KB |
Ok! 1615 queries used. |
4 |
Correct |
125 ms |
512 KB |
Ok! 1493 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
572 KB |
Ok! 1592 queries used. |
2 |
Correct |
138 ms |
580 KB |
Ok! 1594 queries used. |
3 |
Correct |
139 ms |
512 KB |
Ok! 1639 queries used. |
4 |
Correct |
132 ms |
572 KB |
Ok! 1584 queries used. |
5 |
Correct |
124 ms |
512 KB |
Ok! 1454 queries used. |
6 |
Correct |
126 ms |
512 KB |
Ok! 1527 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
576 KB |
Ok! 1611 queries used. |
2 |
Correct |
137 ms |
572 KB |
Ok! 1615 queries used. |