#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
#include "icc.h"
const int maxn = 105;
int n;
int par[maxn];
int root(int x){ return x == par[x] ? x : par[x] = root(par[x]);}
vector<int> comp[maxn];
set<pair<vector<int>, vector<int>>> used;
bool qry(int sa, int sb, vector<int> a, vector<int> b){
int aa[a.size()], bb[b.size()];
copy(a.begin(), a.end(), aa), copy(b.begin(), b.end(), bb);
return query(sa, sb, aa, bb);
}
void run(int _n){
n = _n;
for(int i = 1; i <= n; i++) comp[i].pb(i), par[i] = i;
random_device rd;
mt19937 rng(rd());
for(int rd = 0; rd < n - 1; rd++){
used.clear();
set<int> st;
for(int i = 1; i <= n; i++) st.insert(root(i));
vector<vector<int>> s(2);
vector<vector<int>> id(2);
bool c = false;
while(!c){
s[0].clear(), s[1].clear();
for(auto x : st){
int cur = rng() % 2;
id[cur].pb(x);
for(auto u : comp[x]) s[cur].pb(u);
}
if(!s[0].size() || !s[1].size()) continue;
if(used.count({id[0], id[1]}) || used.count({id[1], id[0]})) continue;
used.insert({id[0], id[1]});
c = qry(s[0].size(), s[1].size(), s[0], s[1]);
}
int l = 0, r = s[0].size() - 1;
while(l != r){
int m = (l + r) / 2;
vector<int> ns;
for(int i = l; i <= m; i++) ns.pb(s[0][i]);
c = qry(ns.size(), s[1].size(), ns, s[1]);
if(c) r = m;
else l = m + 1;
}
vector<int> tmp(1, s[0][l]);
swap(s[0], tmp);
l = 0, r = s[1].size() - 1;
while(l != r){
int m = (l + r) / 2;
vector<int> ns;
for(int i = l; i <= m; i++) ns.pb(s[1][i]);
c = qry(1, ns.size(), s[0], ns);
if(c) r = m;
else l = m + 1;
}
setRoad(s[0][0], s[1][l]);
int a = root(s[0][0]), b = root(s[1][l]);
par[a] = b;
for(auto x : comp[a]) comp[b].pb(x);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
604 KB |
Ok! 98 queries used. |
2 |
Correct |
5 ms |
856 KB |
Ok! 105 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
604 KB |
Ok! 544 queries used. |
2 |
Correct |
42 ms |
732 KB |
Ok! 874 queries used. |
3 |
Correct |
63 ms |
856 KB |
Ok! 824 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
744 KB |
Ok! 1532 queries used. |
2 |
Correct |
143 ms |
760 KB |
Ok! 2150 queries used. |
3 |
Correct |
126 ms |
728 KB |
Ok! 1699 queries used. |
4 |
Correct |
111 ms |
740 KB |
Ok! 1718 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
736 KB |
Ok! 1670 queries used. |
2 |
Correct |
132 ms |
600 KB |
Ok! 1700 queries used. |
3 |
Correct |
116 ms |
600 KB |
Ok! 1922 queries used. |
4 |
Correct |
100 ms |
600 KB |
Ok! 1589 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
119 ms |
772 KB |
Too many queries! 1922 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
113 ms |
852 KB |
Too many queries! 1866 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |