#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
const int MAXN = 512;
vector<int> adj[MAXN];
int state[MAXN]; // 0 still possible, 1 top out, 2 bottom out
vector<int> test;
int target;
void dfs(int x, int par){
if (state[x] == 2) return;
test.push_back(x);
if (state[x] == 0) target--;
for (int nxt : adj[x]){
if (target == 0) break;
if (nxt == par) continue;
dfs(nxt, x);
}
}
int findEgg (int N, vector<pair<int, int>> edges){
for (int i = 1; i <= N; i++){
adj[i].clear();
state[i] = 0;
}
for(auto e : edges){
int a, b; tie(a, b) = e;
adj[a].push_back(b);
adj[b].push_back(a);
}
int poss = N;
while (poss > 1){
target = poss / 2;
test.clear();
dfs(1, -1);
vector<bool> tested(N + 1, 0);
for (int x : test) tested[x] = 1;
if (query(test)){
for (int i = 1; i <= N; i++)
if (state[i] == 0 && !tested[i]){
state[i] = 2;
poss--;
}
}
else{
for (int i = 1; i <= N; i++)
if (state[i] == 0 && tested[i]){
state[i] = 1;
poss--;
}
}
}
for (int i = 1; i <= N; i++)
if (state[i] == 0)
return i;
return -1;
}
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
352 KB |
Number of queries: 8 |
2 |
Correct |
10 ms |
348 KB |
Number of queries: 9 |
3 |
Correct |
15 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
13 ms |
356 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |