#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
typedef int64_t ll;
typedef string str;
int findEgg(int n, vector <pair <int, int>> edges) {
vector <int> g[n + 1];
vector <int> path;
for (auto [a, b] : edges) {
g[a].push_back(b);
g[b].push_back(a);
}
function <void(int, int)> dfs = [&](int v, int p) {
path.push_back(v);
for (int to : g[v]) {
if (to == p) {
continue;
}
dfs(to, v);
}
};
dfs(1, -1);
int l = 0, r = n - 1;
while (l < r) {
int mid = (l + r) >> 1;
vector <int> nodes;
for (int i = 0; i <= mid; ++i) {
nodes.push_back(path[i]);
}
if (query(nodes)) {
r = mid;
} else {
l = mid + 1;
}
}
return path[l];
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
208 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
352 KB |
Number of queries: 8 |
2 |
Correct |
13 ms |
344 KB |
Number of queries: 9 |
3 |
Correct |
24 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
16 ms |
364 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
376 KB |
Number of queries: 9 |
2 |
Correct |
16 ms |
352 KB |
Number of queries: 9 |
3 |
Correct |
22 ms |
352 KB |
Number of queries: 9 |
4 |
Correct |
22 ms |
352 KB |
Number of queries: 9 |