#include <bits/stdc++.h>
#include "library.h"
using namespace std;
const int maxn = 1005;
int n, adj[maxn][maxn];
vector<int> graf[maxn];
int query(int l, int r) {
vector<int> vec(n);
for (int i = l; i <= r; i++)
vec[i] = 1;
return Query(vec);
}
int Count(int l, int r) {
int cnt = 0;
for (int i = l; i <= r; ++i)
for (int j = i + 1; j <= r; ++j)
cnt += adj[i][j];
return r - l + 1 - cnt;
}
void Solve(int N) {
n = N;
vector<pair<int, int>> edges;
for (int i = 1; i < n; ++i) {
int new_edges = Count(0, i) - query(0, i);
for (int rep = 0; rep < new_edges; ++rep) {
int low = 0, high = i - 1, pos = -1;
while (low <= high) {
int mid = low + high >> 1;
if (query(mid, i) != Count(mid, i)) {
pos = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
adj[i][pos] = adj[pos][i] = 1;
edges.push_back({i, pos});
assert(pos != -1);
}
}
for (auto e : edges) {
graf[e.first].push_back(e.second);
graf[e.second].push_back(e.first);
}
vector<int> answer;
function<void(int, int)> Dfs = [&](int u, int fa) {
answer.push_back(u + 1);
for (int v : graf[u]) {
if (v == fa) continue;
Dfs(v, u);
}
};
int rt = 0;
for (int i = 0; i < n; i++) {
if (graf[i].size() == 1) {
rt = i;
}
}
assert(rt != -1);
Dfs(rt, rt);
Answer(answer);
}
Compilation message
library.cpp: In function 'void Solve(int)':
library.cpp:34:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int mid = low + high >> 1;
| ~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1052 KB |
# of queries: 1521 |
2 |
Correct |
25 ms |
960 KB |
# of queries: 1520 |
3 |
Correct |
30 ms |
1088 KB |
# of queries: 1591 |
4 |
Correct |
27 ms |
1020 KB |
# of queries: 1590 |
5 |
Correct |
32 ms |
1000 KB |
# of queries: 1596 |
6 |
Correct |
32 ms |
1088 KB |
# of queries: 1600 |
7 |
Correct |
20 ms |
1040 KB |
# of queries: 1587 |
8 |
Correct |
26 ms |
1052 KB |
# of queries: 1517 |
9 |
Correct |
26 ms |
1092 KB |
# of queries: 1595 |
10 |
Correct |
15 ms |
816 KB |
# of queries: 949 |
11 |
Correct |
0 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
200 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
328 KB |
# of queries: 5 |
14 |
Correct |
0 ms |
328 KB |
# of queries: 9 |
15 |
Correct |
1 ms |
320 KB |
# of queries: 61 |
16 |
Correct |
3 ms |
328 KB |
# of queries: 136 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1052 KB |
# of queries: 1521 |
2 |
Correct |
25 ms |
960 KB |
# of queries: 1520 |
3 |
Correct |
30 ms |
1088 KB |
# of queries: 1591 |
4 |
Correct |
27 ms |
1020 KB |
# of queries: 1590 |
5 |
Correct |
32 ms |
1000 KB |
# of queries: 1596 |
6 |
Correct |
32 ms |
1088 KB |
# of queries: 1600 |
7 |
Correct |
20 ms |
1040 KB |
# of queries: 1587 |
8 |
Correct |
26 ms |
1052 KB |
# of queries: 1517 |
9 |
Correct |
26 ms |
1092 KB |
# of queries: 1595 |
10 |
Correct |
15 ms |
816 KB |
# of queries: 949 |
11 |
Correct |
0 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
200 KB |
# of queries: 2 |
13 |
Correct |
1 ms |
328 KB |
# of queries: 5 |
14 |
Correct |
0 ms |
328 KB |
# of queries: 9 |
15 |
Correct |
1 ms |
320 KB |
# of queries: 61 |
16 |
Correct |
3 ms |
328 KB |
# of queries: 136 |
17 |
Correct |
844 ms |
4192 KB |
# of queries: 10296 |
18 |
Correct |
795 ms |
4180 KB |
# of queries: 10166 |
19 |
Correct |
792 ms |
4332 KB |
# of queries: 10254 |
20 |
Correct |
688 ms |
3948 KB |
# of queries: 9626 |
21 |
Correct |
599 ms |
3752 KB |
# of queries: 9030 |
22 |
Correct |
855 ms |
4148 KB |
# of queries: 10292 |
23 |
Correct |
833 ms |
4104 KB |
# of queries: 10279 |
24 |
Correct |
175 ms |
2240 KB |
# of queries: 4794 |
25 |
Correct |
793 ms |
4164 KB |
# of queries: 10059 |
26 |
Correct |
623 ms |
3880 KB |
# of queries: 9396 |
27 |
Correct |
171 ms |
2408 KB |
# of queries: 4781 |
28 |
Correct |
411 ms |
4288 KB |
# of queries: 9976 |
29 |
Correct |
411 ms |
4396 KB |
# of queries: 9965 |
30 |
Correct |
419 ms |
4396 KB |
# of queries: 9976 |