#include<bits/stdc++.h>
#include "grader.h"
using namespace std;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
vector<vi> AdjList;
vi qr;
vector<bool> num,ck;
int cur,cnt,n,tmp;
void dfs(int v, int p) {
if(tmp==cur) return;
if(ck[v]) cur++;
qr.push_back(v);
for(int u: AdjList[v]) {
if(u==p) continue;
else dfs(u,v);
}
}
int findEgg(int n, vii edges) {
AdjList.assign(n+1,vi());
num.assign(n+1,-1);
ck.assign(n+1,1);
cnt=n;
for(ii t: edges) {
AdjList[t.first].push_back(t.second);
AdjList[t.second].push_back(t.first);
}
while(cnt!=1) {
tmp=(cnt+1)/2;
cur=0;
qr.clear();
dfs(1,1);
if(query(qr)) {
for(int i=1 ; i<=n ; i++) num[i]=0;
for(int i: qr) num[i]=ck[i];
for(int i=1 ; i<=n ; i++) ck[i]=num[i];
cnt=tmp;
}
else {
for(int i: qr) {
ck[i]=0;
}
cnt-=tmp;
}
}
for(int i=1 ; i<=n ; i++) {
if(ck[i]) return i;
}
}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, vii)':
eastereggs.cpp:50: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 |
256 KB |
Number of queries: 4 |
3 |
Correct |
6 ms |
256 KB |
Number of queries: 4 |
4 |
Correct |
5 ms |
256 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
384 KB |
Number of queries: 8 |
2 |
Correct |
18 ms |
256 KB |
Number of queries: 9 |
3 |
Correct |
25 ms |
384 KB |
Number of queries: 9 |
4 |
Correct |
23 ms |
384 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
384 KB |
Number of queries: 9 |
2 |
Correct |
23 ms |
384 KB |
Number of queries: 9 |
3 |
Correct |
24 ms |
384 KB |
Number of queries: 9 |
4 |
Correct |
20 ms |
384 KB |
Number of queries: 9 |