#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
#define maxn 520
#define pb push_back
#define sz(x) ((int)x.size())
typedef pair<int,int> ii;
int mark[maxn],take[maxn];
vector<int> AL[maxn];
void dfs(int u,int p,vector<int> &s,int &t){
if(mark[u])s.pb(u);
else if(t>0)s.pb(u),--t;
else return;
for(int v:AL[u]){
if(v==p)continue;
dfs(v,u,s,t);
}
}
int findEgg(int N,vector<ii> bridges){
memset(mark,0,sizeof mark);
for(int i=1;i<=N;++i)AL[i].clear();
for(auto[u,v]:bridges){
AL[u].pb(v);
AL[v].pb(u);
}
while(true){
int rem=0;
for(int i=1;i<=N;++i){
if(!mark[i])++rem;
}
if(rem==1)break;
rem/=2;
vector<int> v;
dfs(1,-1,v,rem);
int res=query(v);
for(int i:v)take[i]=1;
for(int i=1;i<=N;++i){
if(res==0&&take[i]==1)mark[i]=1;
else if(res==1&&take[i]==0)mark[i]=1;
}
for(int i:v)take[i]=0;
}
for(int i=1;i<=N;++i){
if(!mark[i])return i;
}
}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
51 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
356 KB |
Number of queries: 8 |
2 |
Correct |
13 ms |
336 KB |
Number of queries: 9 |
3 |
Correct |
20 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
18 ms |
336 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
384 KB |
Number of queries: 9 |
2 |
Correct |
18 ms |
352 KB |
Number of queries: 9 |
3 |
Correct |
19 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
19 ms |
352 KB |
Number of queries: 9 |