//https://oj.uz/problem/view/CEOI16_icc
#include<bits/stdc++.h>
#include "icc.h"
const int N = 105;
using namespace std;
vector <int> mv[N];
int pset[N], cnt = 0;
int find(int i) {return ((pset[i] == i) ? i : pset[i] = find(pset[i]));}
void dsu(int i, int j){
i = find(i); j = find(j);
if (i == j) return;
if (mv[i].size() > mv[j].size()) swap(i, j);
for (auto x : mv[i]) mv[j].push_back(x);
pset[i] = j;
}
bool query(vector <int> &a, vector <int> &b){
int A[N], B[N], siza = a.size(), sizb = b.size();
for (int i = 0; i < siza; i++) A[i] = a[i];
for (int i = 0; i < sizb; i++) B[i] = b[i];
return query(siza, sizb, A, B);
}
void find(vector <int>&a, vector <int>& b){
if (a.size() == 1) return;
int siz = (int)a.size() / 2;
vector <int> x; x.clear();
for (int i = 0; i < siz; i++) x.push_back(a[i]);
cnt++;
if (!query(x, b)){
x.clear();
for (int i = siz; i < (int)a.size(); i++) x.push_back(a[i]);
}
a.swap(x);
find(a, b);
}
void cal(vector <int>& a, vector <int>& b){
cnt = 0; find(a, b);
cnt = 0; find(b, a);
setRoad(a[0], b[0]); dsu(a[0], b[0]);
}
void run(int n){
for (int i = 1; i <= n; i++) pset[i] = i, mv[i].push_back(i);
while (1){
vector <int> A;
for (int i = 1; i <= n; i++) if (pset[i] == i) A.push_back(i);
for (int i = 0; (1 << i) < (int)A.size(); i++){
vector <int> a, b;
for (int j = 0; j < (int)A.size(); j++){
if ((j >> i)&1){
for (auto x : mv[A[j]]) a.push_back(x);
}
else{
for (auto x : mv[A[j]]) b.push_back(x);
}
}
if (query(a, b)){
cal(a, b); break;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
512 KB |
Ok! 94 queries used. |
2 |
Correct |
7 ms |
512 KB |
Ok! 102 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
640 KB |
Ok! 529 queries used. |
2 |
Correct |
44 ms |
512 KB |
Ok! 686 queries used. |
3 |
Correct |
42 ms |
512 KB |
Ok! 685 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
564 KB |
Ok! 1490 queries used. |
2 |
Correct |
133 ms |
512 KB |
Ok! 1672 queries used. |
3 |
Correct |
117 ms |
632 KB |
Ok! 1555 queries used. |
4 |
Correct |
126 ms |
560 KB |
Ok! 1565 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
600 KB |
Ok! 1494 queries used. |
2 |
Correct |
169 ms |
604 KB |
Ok! 1469 queries used. |
3 |
Correct |
127 ms |
512 KB |
Ok! 1671 queries used. |
4 |
Correct |
111 ms |
556 KB |
Ok! 1496 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
564 KB |
Ok! 1653 queries used. |
2 |
Correct |
127 ms |
632 KB |
Ok! 1648 queries used. |
3 |
Correct |
131 ms |
560 KB |
Ok! 1656 queries used. |
4 |
Correct |
127 ms |
512 KB |
Ok! 1598 queries used. |
5 |
Correct |
116 ms |
512 KB |
Ok! 1504 queries used. |
6 |
Correct |
127 ms |
512 KB |
Ok! 1555 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
130 ms |
512 KB |
Too many queries! 1676 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |