#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
vector<int> ask;
vector<int> adj[1005];
bool used[1005];
bool take[1005];
bool bad[1005];
int sz=0;
int cnt=0;
void dfs(int node, int fa)
{
if(cnt==sz/2) return;
if(!used[node])
{
cnt++;
}
ask.push_back(node);
for(auto i:adj[node])
{
if(bad[i]||i==fa) continue;
dfs(i,node);
}
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
ask.clear();
memset(used, 0, sizeof(used));
memset(bad, 0, sizeof(bad));
for(int i=1; i<=N; i++)
{
adj[i].clear();
}
sz=N;
for(auto i:bridges)
{
adj[i.first].push_back(i.second);
adj[i.second].push_back(i.first);
}
while(true)
{
ask.clear();
if(sz==1)
{
for(int i=1; i<=N; i++)
{
if(!bad[i]&&!used[i])
{
return i;
}
}
}
else
{
cnt=0;
dfs(1,1);
if(query(ask))
{
sz=cnt;
bool lay[1000];
memset(lay, 0, sizeof(lay));
for(auto i:ask)
{
lay[i]=1;
}
for(int i=1; i<=N; i++)
{
if(!lay[i])
{
bad[i]=true;
}
}
}
else
{
sz-=cnt;
for(auto i:ask)
{
used[i]=true;
}
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Number of queries: 4 |
2 |
Correct |
2 ms |
256 KB |
Number of queries: 4 |
3 |
Correct |
2 ms |
384 KB |
Number of queries: 4 |
4 |
Correct |
3 ms |
256 KB |
Number of queries: 4 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
364 KB |
Number of queries: 8 |
2 |
Correct |
10 ms |
384 KB |
Number of queries: 9 |
3 |
Correct |
16 ms |
256 KB |
Number of queries: 9 |
4 |
Correct |
16 ms |
384 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
384 KB |
Number of queries: 9 |
2 |
Correct |
16 ms |
256 KB |
Number of queries: 9 |
3 |
Correct |
18 ms |
256 KB |
Number of queries: 9 |
4 |
Correct |
17 ms |
256 KB |
Number of queries: 9 |