#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){
int cnt = N;
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));
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] = exist[v];
for(int i=1;i<=N;++i) exist[i] = nxt[i];
cnt = now;
}else{
for(auto v:call) exist[v] = 0;
cnt -= now;
}
}
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]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Number of queries: 4 |
2 |
Correct |
5 ms |
384 KB |
Number of queries: 4 |
3 |
Correct |
5 ms |
384 KB |
Number of queries: 4 |
4 |
Correct |
5 ms |
384 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
412 KB |
Number of queries: 8 |
2 |
Correct |
14 ms |
384 KB |
Number of queries: 9 |
3 |
Correct |
26 ms |
384 KB |
Number of queries: 9 |
4 |
Correct |
19 ms |
384 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
384 KB |
Number of queries: 9 |
2 |
Correct |
19 ms |
384 KB |
Number of queries: 9 |
3 |
Correct |
24 ms |
384 KB |
Number of queries: 9 |
4 |
Correct |
22 ms |
384 KB |
Number of queries: 9 |