#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
const int sz = 1000;
#define pii pair<int,int>
vector<int> g[sz], call;
int need, now;
bool exist[sz], nxt[sz];
void dfs(int p,int u){
if(now==need) return;
if(exist[u]) ++now;
call.push_back(u);
for(auto v:g[u]) if(v!=p) dfs(u,v);
}
//int query(vector<int> e){
// for(auto v:e) cout << v << " ";
// cout << endl;
// int verd;
// cin >> verd;
// return verd;
//}
int findEgg(int N, vector<pii> bridges){
for(int i=1;i<=N;++i) g[i].clear();
for(int i=0;i<N-1;++i){
g[bridges[i].first].push_back(bridges[i].second);
g[bridges[i].second].push_back(bridges[i].first);
}
memset(exist,true,sizeof(exist));
int cnt = N;
while(cnt!=1){
need = (cnt+1)/2, now = 0;
call.clear();
dfs(1,1);
if(query(call)){
memset(nxt,false,sizeof(nxt));
for(auto v:call) nxt[v] = 1;
for(int i=1;i<=N;++i) exist[i] = nxt[i];
cnt = call.size();
}else{
for(auto v:call) exist[v] = 0;
cnt -= call.size();
}
}
for(int i=1;i<=N;++i) if(exist[i]) return i;
}
//signed main(){
// int n;
// cin >> n;
// vector<pii> e(n-1);
// for(int i=0;i<n-1;++i) cin >> e[i].first >> e[i].second;
// cout << findEgg(n,e);
//}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |