# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
744258 | MON | Library (JOI18_library) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
void Solve(int N)
{
vector<int> m(N,0); int queries = 0;
vector<int> vecini[N + 1]; int luat[N] = {0};
for(int i = 0 ; i < N - 1 ; i++)
{
for(int j = 0 ; j < N ; j++)
{
m[i] = 1;
m[j] = 1;
int sunt = Query(m) & 1; queries++;
if(sunt) vecini[i].emplace_back(j),vecini[j].emplace_back(i);
m[i] = 0;
m[j] = 0;
}
}
vector<int> ans; if(queries > 20000) exit(1);
for(int i = 0; i < N ; i++)
{
if(vecini[i].size() == 1)
{
ans.emplace_back(i + 1);
luat[i] = 1; break;
}
}
while(ans.size() != N)
{
for(auto &it : vecini[ans.back()])
{
if(!luat[it])
{
luat[it] = 1;
ans.emplace_back(it + 1);
break;
}
}
}
Answer(ans);
}