#include<bits/stdc++.h>
#include "grader.h"
using namespace std;
using pii=pair<int,int>;
int N;
vector<int> adjlist[555];
bool seen[555];
vector<int> preorder={-1};
void init(){
fill(seen,seen+555,0);
fill(adjlist,adjlist+555,(vector<int>){});
preorder={-1};
}
void dfs(int node){
seen[node]=1;
preorder.push_back(node);
for(int child:adjlist[node]){
if(!seen[child]) dfs(child);
}
}
int bsearch(){
int lo=1;
int hi=N;
vector<int> query_vector={1}; // always a prefix [1..i]
// while(lo!=hi){
// int mid=(lo+hi)/2;
// while(!query_vector.empty() && query_vector[query_vector.size()-1]>lo) query_vector.pop_back();
// for(int i=lo+1;i<=mid;i++){
// query_vector.push_back(i);
// }
// if(query(query_vector)) hi=mid;
// else lo=mid+1;
// }
return lo;
}
int findEgg(int _N, vector<pii> edges){
N=_N;
init();
for(pii i:edges){
int a,b;
tie(a,b)=i;
adjlist[a].push_back(b);
adjlist[b].push_back(a);
}
dfs(1);
return bsearch();
}
Compilation message
eastereggs.cpp: In function 'int bsearch()':
eastereggs.cpp:30:9: warning: unused variable 'hi' [-Wunused-variable]
30 | int hi=N;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
The found island is incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
The found island is incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
336 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |