# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1134198 | 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].push_back(j);
s[j].push_back(i);
}
}
}
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, 0);
while(idx < n) {
ans[idx++] = start + 1;
was[start] = 1;
for(auto it : s[start]) {
if(was[it]) {
continue;
}
start = it;
}
}
Answer(ans);
}