-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathd.cpp
79 lines (75 loc) · 1.85 KB
/
d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
#define endl "\n"
#define eat cin
#define moo cout
using namespace std;
int T, N, K;
vector<int> sub[1000], q;
int qry(){
if(q.empty()) return -1;
moo << "? " << q.size();
for(int i : q) moo << ' ' << i;
q.clear();
moo << endl;
moo.flush();
int ret; eat >> ret;
return ret;
}
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> T;
while(T--){
eat >> N >> K;
for(int i = 0; i < K; i++){
sub[i].clear();
int c; eat >> c;
for(int j = 0; j < c; j++){
int x; eat >> x;
sub[i].push_back(x);
}
}
for(int i = 1; i <= N; i++) q.push_back(i);
int mx = qry();
int lo = 1, hi = N, mid = 0, ans = 0;
while(lo <= hi){
mid = (lo + hi) / 2;
for(int i = 1; i < mid; i++){
q.push_back(i);
}
int cur = qry();
if(cur < mx){
ans = mid, lo = mid+1;
}else{
hi = mid-1;
}
}
vector<int> pwd;
for(int i = 0; i < K; i++){
bool ok = true;
for(int j : sub[i]){
if(j == ans) ok = false;
}
if(ok){
pwd.push_back(mx);
}else{
bool rm[N];
fill(rm, rm+N, true);
for(int j : sub[i]){
rm[j-1] = false;
}
for(int j = 0; j < N; j++){
if(rm[j]) q.push_back(j+1);
}
pwd.push_back(qry());
}
}
moo << '!';
for(int i = 0; i < K; i++){
moo << ' ' << pwd[i];
}
moo << endl;
moo.flush();
string s; eat >> s;
if(s != "Correct") break;
}
}