-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE.cpp
66 lines (63 loc) · 1.33 KB
/
E.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
#include "bits/stdc++.h"
using namespace std;
int sub[555];
vector <int> done;
typedef pair <int, int> pii;
int par[555];
int query(vector <int> p, vector <int> q, int v) {
cout << p.size() << endl;
for(int i = 0; i < p.size(); i++) cout << p[i] << ' ';
cout << endl;
cout << q.size() << endl;
for(int i = 0; i < q.size(); i++) cout << q[i] << ' ';
cout << endl;
cout << v << endl;
int ans;
cin >> ans;
return ans;
}
int search(int b, int e, int val) {
if(b == e) {
return b;
}
int m = (b + e) >> 1;
vector <int> v;
for(int i = 0; i <= m; i++) {
v.emplace_back(done[i]);
}
if(query({1}, v, val)) return search(b, m, val);
else return search(m + 1, e, val);
}
int main(int argc, char const *argv[])
{
int n;
cin >> n;
vector <int> v;
for(int i = 2; i <= n; i++) {
v.emplace_back(i);
}
sub[1] = n;
for(int i = 2; i <= n; i++) {
sub[i] = query({1}, v, i);
}
vector <pii> A;
for(int i = 1; i <= n; i++) {
A.emplace_back(sub[i], i);
}
sort(A.begin(), A.end());
for(auto i : A) {
int cur = i.first - 1;
while(cur > 0 && !done.empty()) {
int x = search(0, done.size() - 1, i.second);
par[done[x]] = i.second;
cur -= sub[done[x]];
done.erase(done.begin() + x);
}
done.emplace_back(i.second);
}
cout << "ANSWER" << endl;
for(int i = 2; i <= n; i++) {
cout << par[i] << ' ' << i << endl;
}
return 0;
}