#include <bits/stdc++.h>
#include "grader.h"
// #include "grader.cpp"
using namespace std;
vector<int> adj[520];
vector<int> v;
void dfs(int u, int p){
v.push_back(u);
for(auto x : adj[u]){
if(x != p)
dfs(x, u);
}
}
int findEgg(int N, vector<pair<int, int>> bridges){
ios_base::sync_with_stdio(0);
for(int i=0; i<N-1; i++){
int u = bridges[i].first;
int v = bridges[i].second;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
int ans = v[N - 1];
int l = 0, r = N - 2;
while(l <= r){
vector<int> islands;
int mid = (l + r) / 2;
for(int i=0; i<=mid; i++)
islands.push_back(v[i]);
if(query(islands) == 1){
ans = v[mid];
r = mid - 1;
}
else
l = mid + 1;
}
v.clear();
for(int i=1; i<=N; i++)
adj[i].clear();
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 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 |
5 ms |
336 KB |
Number of queries: 8 |
2 |
Correct |
13 ms |
468 KB |
Number of queries: 9 |
3 |
Correct |
17 ms |
376 KB |
Number of queries: 9 |
4 |
Correct |
18 ms |
336 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
388 KB |
Number of queries: 9 |
2 |
Correct |
13 ms |
368 KB |
Number of queries: 9 |
3 |
Correct |
20 ms |
376 KB |
Number of queries: 9 |
4 |
Correct |
15 ms |
380 KB |
Number of queries: 9 |