#include <bits/stdc++.h>
#include "library.h"
//#include "grader.cpp"
using namespace std;
// Query(M) = мин кол-во чтобы вырезать нужные числа
const int MAXN = 1005;
vector <int> g[MAXN];
vector <int> res;
vector <int> need;
int n;
int ask(int a, int b) {
for (int i = 0; i < n; i++) {
need[i] = 0;
}
need[a - 1] = 1;
need[b - 1] = 1;
int x = Query(need);
return x;
}
void dfs(int v, int par, int ind) {
res[ind] = v;
for (int to : g[v]) {
if (to != par) {
dfs(to, v, ind + 1);
}
}
}
void Solve(int N) {
if (N == 1) {
Answer(vector <int> ({1}));
return;
}
n = N;
vector <int> deg(n + 1, 0);
res.resize(n);
need.resize(n);
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (ask(i, j) == 1) {
g[i].push_back(j);
g[j].push_back(i);
deg[i]++, deg[j]++;
}
}
}
int root = -1;
int sz[3] = {0, 0, 0};
for (int i = 1; i <= n; i++) {
sz[deg[i]]++;
if (deg[i] == 1) {
root = i;
}
}
dfs(root, -1, 0);
if ((int)res.size() != n || !(sz[1] == 2 && sz[2] == n - 2)) {
while (1);
}
Answer(res);
}
/*
5
4 2 5 3 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
364 KB |
# of queries: 18336 |
2 |
Correct |
205 ms |
496 KB |
# of queries: 18145 |
3 |
Correct |
336 ms |
364 KB |
# of queries: 19900 |
4 |
Correct |
242 ms |
364 KB |
# of queries: 19900 |
5 |
Correct |
293 ms |
364 KB |
# of queries: 19900 |
6 |
Correct |
208 ms |
404 KB |
# of queries: 19900 |
7 |
Correct |
261 ms |
404 KB |
# of queries: 19900 |
8 |
Correct |
256 ms |
492 KB |
# of queries: 18528 |
9 |
Correct |
299 ms |
404 KB |
# of queries: 19701 |
10 |
Correct |
143 ms |
364 KB |
# of queries: 8256 |
11 |
Correct |
0 ms |
364 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
364 KB |
# of queries: 1 |
13 |
Correct |
0 ms |
364 KB |
# of queries: 3 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 6 |
15 |
Correct |
2 ms |
364 KB |
# of queries: 105 |
16 |
Correct |
6 ms |
364 KB |
# of queries: 351 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
364 KB |
# of queries: 18336 |
2 |
Correct |
205 ms |
496 KB |
# of queries: 18145 |
3 |
Correct |
336 ms |
364 KB |
# of queries: 19900 |
4 |
Correct |
242 ms |
364 KB |
# of queries: 19900 |
5 |
Correct |
293 ms |
364 KB |
# of queries: 19900 |
6 |
Correct |
208 ms |
404 KB |
# of queries: 19900 |
7 |
Correct |
261 ms |
404 KB |
# of queries: 19900 |
8 |
Correct |
256 ms |
492 KB |
# of queries: 18528 |
9 |
Correct |
299 ms |
404 KB |
# of queries: 19701 |
10 |
Correct |
143 ms |
364 KB |
# of queries: 8256 |
11 |
Correct |
0 ms |
364 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
364 KB |
# of queries: 1 |
13 |
Correct |
0 ms |
364 KB |
# of queries: 3 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 6 |
15 |
Correct |
2 ms |
364 KB |
# of queries: 105 |
16 |
Correct |
6 ms |
364 KB |
# of queries: 351 |
17 |
Runtime error |
403 ms |
364 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
18 |
Halted |
0 ms |
0 KB |
- |