# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
436265 | 2021-06-24T11:17:01 Z | LouayFarah | Library (JOI18_library) | C++14 | 0 ms | 0 KB |
#include "bits/stdc++.h" #include "library.h" using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second void Solve(int n) { if(n==1) { vector<int> res(1); res[0] = 1; return res; } vector<pair<int, int>> arr; vector<int> m(n, 0); for(int i = 1; i<=n; i++) { for(int j = i+1; j<=n; j++) { m.assign(n, 0); m[i-1] = 1, m[j-1] = 1; int cnt = Query(m); if(cnt==2) { arr.pb(mp(i, j)); } } } vector<int> adj[n+1]; for(int i = 0; i<(int)arr.size(); i++) { adj[arr[i].fi].pb(arr[i].se); adj[arr[i].se].pb(arr[i].fi); } int beg = 1; for(int i = 1; i<=n; i++) { if((int)adj[i].size()==1) { beg = 1; break; } } vector<bool> visited(n+1, false); queue<int> q; q.push(beg); visited[beg] = true; vector<int> res; while(!q.empty()) { int u = q.front(); q.pop(); res.pb(u); for(auto v: adj[u]) { if(visited[v]) continue; visited[v] = true; q.push(v); } } Answer(res); }