#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
using namespace std;
#include "grader.h"
vector<int> adj[1000];
vector<int> sub(1000);
vector<bool> let(1000, false);
void dfs(int x, int pre){
sub[x] = 1;
for(auto y : adj[x]){
if(y == pre || !let[y]) continue;
dfs(y, x);
sub[x] += sub[y];
}
}
int find_centroid(int x, int pre, int sum){
for(auto y : adj[x]){
if(y == pre || !let[y]) continue;
if(sub[y] > sum / 2) return find_centroid(y, x, sum);
}
return x;
}
void addall(int x, int pre, vector<int>& A){
A.pb(x);
for(auto y : adj[x]){
if(y == pre || !let[y]) continue;
addall(y, x, A);
}
}
void split(int x, int pre, int s, vector<int>&L,vector<int>&R){
L.pb(x);
R.pb(x);
s--;
for(auto y : adj[x]){
if(y == pre || !let[y]) continue;
if(s >= sub[y]){
addall(y, x, L);
s -= sub[y];
}
else {
addall(y, x, R);
}
}
}
int solve(vector<int> comp){
for(auto x : comp) let[x] = true;
if(comp.empty()) assert(0);
dfs(comp[0], -1);
int root = find_centroid(comp[0], -1, sub[comp[0]]);
dfs(root, -1);
if(sz(comp) == 1) return root;
vector<int> left, right;
split(root, -1, sub[root] / 2 + 1, left, right);
for(auto x : comp) let[x] = false;
if(right.size() == 1){
for(auto x : left){
if(query({x})) return x;
}
assert(0);
}
if(left.size() == 1){
for(auto x : right){
if(query({x})) return x;
}
assert(0);
}
if(query(left)){
return solve(left);
}
else {
return solve(right);
}
}
void init(vector < pair < int, int > >& bridges){
static bool yes = true;
if(yes)
for(auto p : bridges){
adj[p.first].pb(p.second);
adj[p.second].pb(p.first);
}
yes = false;
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
init(bridges);
vector<int> arr;
for(int i = 1; i <= N; i++) arr.pb(i), let[i] = false;
return solve(arr);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
384 KB |
Number of queries: 6 |
2 |
Partially correct |
2 ms |
384 KB |
Number of queries: 7 |
3 |
Partially correct |
1 ms |
384 KB |
Number of queries: 6 |
4 |
Partially correct |
2 ms |
384 KB |
Number of queries: 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
5 ms |
384 KB |
Number of queries: 10 |
2 |
Partially correct |
14 ms |
384 KB |
Number of queries: 13 |
3 |
Partially correct |
13 ms |
384 KB |
Number of queries: 12 |
4 |
Partially correct |
13 ms |
384 KB |
Number of queries: 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
15 ms |
384 KB |
Number of queries: 11 |
2 |
Partially correct |
12 ms |
384 KB |
Number of queries: 13 |
3 |
Partially correct |
15 ms |
384 KB |
Number of queries: 12 |
4 |
Partially correct |
12 ms |
384 KB |
Number of queries: 11 |