#include <bits/stdc++.h>
#include "library.h"
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
int n;
vector<pair<int,int>> ed;
vector<int> ans, adj[1500];
void dfs(int s, int p){
ans.pb(s);
for(auto u : adj[s])
if(u!=p) dfs(u,s);
}
int chk(int l, int r, int q){
int ans = 0;
for(auto [a,b] : ed) ans+=a>=l and b<=r;
return r-l+1-q-ans;
}
void Solve(int N)
{
n = N; int tot = 0;
vector<int> M(N,0);
while(tot<n-1){
int l = 1, r = n, x = 1;
while(l<r){
int mid = (l+r)/2;
fill(begin(M),begin(M)+mid,1);
int e = chk(1,mid,Query(M));
if(e>0) r=mid, x=e;
else l=mid+1;
fill(begin(M),begin(M)+mid,0);
}
int i = l;
while(x--){
tot++; l = 1, r=i-1;
while(l<r){
int mid = (l+r+1)/2;
fill(begin(M)+mid-1,begin(M)+i,1);
if(chk(mid,i,Query(M))>0) l=mid;
else r=mid-1;
fill(begin(M)+mid-1,begin(M)+i,0);
}
adj[i].pb(l), adj[l].pb(i), ed.pb({l,i});
}
}
for(int i = 1; i <= N; i++){
if(sz(adj[i])==1){
dfs(i,-1), Answer(ans);
return;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
324 KB |
# of queries: 2263 |
2 |
Correct |
20 ms |
340 KB |
# of queries: 2309 |
3 |
Correct |
28 ms |
336 KB |
# of queries: 2398 |
4 |
Correct |
30 ms |
336 KB |
# of queries: 2452 |
5 |
Correct |
29 ms |
336 KB |
# of queries: 2432 |
6 |
Correct |
27 ms |
336 KB |
# of queries: 2441 |
7 |
Correct |
31 ms |
344 KB |
# of queries: 2433 |
8 |
Correct |
27 ms |
344 KB |
# of queries: 2317 |
9 |
Correct |
29 ms |
332 KB |
# of queries: 2400 |
10 |
Correct |
16 ms |
320 KB |
# of queries: 1395 |
11 |
Incorrect |
0 ms |
216 KB |
Wrong Answer [7] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
324 KB |
# of queries: 2263 |
2 |
Correct |
20 ms |
340 KB |
# of queries: 2309 |
3 |
Correct |
28 ms |
336 KB |
# of queries: 2398 |
4 |
Correct |
30 ms |
336 KB |
# of queries: 2452 |
5 |
Correct |
29 ms |
336 KB |
# of queries: 2432 |
6 |
Correct |
27 ms |
336 KB |
# of queries: 2441 |
7 |
Correct |
31 ms |
344 KB |
# of queries: 2433 |
8 |
Correct |
27 ms |
344 KB |
# of queries: 2317 |
9 |
Correct |
29 ms |
332 KB |
# of queries: 2400 |
10 |
Correct |
16 ms |
320 KB |
# of queries: 1395 |
11 |
Incorrect |
0 ms |
216 KB |
Wrong Answer [7] |
12 |
Halted |
0 ms |
0 KB |
- |