# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1134201 | lopkus | Library (JOI18_library) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
void Solve(int n){
vector<int> s[n + 1];
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
vector<int> ask(n, 0);
ask[i] = 1;
ask[j] = 1;
int u = query(ask);
if(u) {
s[i + 1].push_back(j + 1);
s[j + 1].push_back(i + 1);
}
}
}
int start = - 1;
for(int i = 0 ; i < n; i++) {
if(s[i].size() == 1) {
start = i;
}
}
vector<int> ans(n);
int idx = 0;
vector<int> was(n + 1, 0);
for(int i = 0; i < n; i++) {
ans[i] = start;
was[start] = 1;
int next = - 1;
for(auto it : s[start]) {
if(was[it]) {
continue;
}
next = it;
break;
}
start = next;
}
Answer(ans);
}