# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
656571 | 2022-11-08T01:48:23 Z | haojiandan | Library (JOI18_library) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "library.h" using namespace std; int n,p[1010]; vector<int> g[1010]; int tot,d[1010]; void dfs(int u,int p) { d[++tot]=u; for (int &v : g[u]) if (v!=p) dfs(v,u); } void Solve(int _n) { n=_n; if (n==1) return {1}; for (int i=1;i<=n;i++) { for (int j=i+1;j<=n;j++) p[j]=j; random_shuffle(p+i+1,p+n+1); for (int j=i+1;j<=n&&(int)g[i].size()<2;j++) { vector<int> Q(n); Q[i-1]=Q[p[j]-1]=1; if (Query(Q)==1) g[i].push_back(p[j]),g[p[j]].push_back(i); } } int x; for (int i=1;i<=n;i++) if ((int)g[i].size()==1) { x=i; break; } dfs(x,0); vector<int> ans(n); for (int i=1;i<=n;i++) ans[i-1]=d[i]; Answer(ans); }