#include <bits/stdc++.h>
#include "grader.h"
#include <vector>
using namespace std;
int x;
void primera(int n,vector<vector<int> >&a,vector<int>&r,vector<bool>&v){
if(r.size()<x){
r.push_back(n+1);
v[n]=true;
for(int i:a[n]){
if(!v[i]){
primera(i,a,r,v);
}
}
}
}
void bus(int n,vector<vector<int> >&a,vector<int>&r,vector<bool>&v,vector<int>&p){
if(x!=0){
if(p[n]==1){
x--;
}
v[n]=true;
r.push_back(n+1);
for(int i:a[n]){
if(!v[i]){
bus(i,a,r,v,p);
}
}
}
}
int findEgg (int N, vector < pair < int, int > > bridges)
{ vector<vector<int> >a(N);
for(int i=0;i<N-1;i++){
int k=bridges[i].first;
k--;
int h=bridges[i].second;
h--;
a[k].push_back(h);
a[h].push_back(k);
}
int y=N;
if(y%2==0)y=y/2;
else y=y/2+1;
x=y;
vector<int>r;
vector<int>p(N,0);
vector<bool>v(N,false);
primera(0,a,r,v);
if(query(r)==1){
for(int i=0;i<N;i++){
if(v[i]){
p[i]=1;
}
}
}
else{
for(int i=0;i<N;i++){
if(!v[i]){
p[i]=1;
}
}
}
while(y>1){
if(y%2==0)y=y/2;
else y=y/2+1;
x=y;
r.clear();
v.assign(N,false);
bus(0,a,r,v,p);
if(query(r)==1){
for(int i=0;i<N;i++){
if(!v[i])p[i]=0;
}
}
else{
for(int i=0;i<N;i++){
if(v[i])p[i]=0;
}
}
}
for(int i=0;i<N;i++){
if(p[i]==1){
x=i+1;
break;
}
}
return x;
}
Compilation message
eastereggs.cpp: In function 'void primera(int, std::vector<std::vector<int> >&, std::vector<int>&, std::vector<bool>&)':
eastereggs.cpp:7:12: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
7 | if(r.size()<x){
| ~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
348 KB |
Number of queries: 8 |
2 |
Correct |
18 ms |
340 KB |
Number of queries: 9 |
3 |
Correct |
31 ms |
328 KB |
Number of queries: 9 |
4 |
Correct |
21 ms |
344 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
416 KB |
Number of queries: 9 |
2 |
Correct |
24 ms |
340 KB |
Number of queries: 9 |
3 |
Correct |
24 ms |
328 KB |
Number of queries: 9 |
4 |
Correct |
28 ms |
332 KB |
Number of queries: 9 |