#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
void get_preorder(vector<vector<int>> const &g, int u, int p, vector<int> &trav)
{
trav.push_back(u + 1);
for (int const &v : g[u])
if (v != p)
get_preorder(g, v, u, trav);
}
int findEgg(int n, vector<pair<int, int>> edges)
{
vector<vector<int>> g(n);
for (auto const &[u, v] : edges)
{
g[u - 1].push_back(v - 1);
g[v - 1].push_back(u - 1);
}
vector<int> preorder;
get_preorder(g, 0, -1, preorder);
size_t a = 0, b = n - 1;
while (a < b)
{
size_t mid = (a + b + 1) / 2;
if (query(vector<int>(preorder.begin(), preorder.begin() + mid)))
b = mid - 1;
else
a = mid;
}
return preorder[a];
}
# |
결과 |
실행 시간 |
메모리 |
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 |
5 ms |
348 KB |
Number of queries: 8 |
2 |
Correct |
13 ms |
336 KB |
Number of queries: 9 |
3 |
Correct |
18 ms |
352 KB |
Number of queries: 9 |
4 |
Correct |
16 ms |
344 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
464 KB |
Number of queries: 9 |
2 |
Correct |
15 ms |
336 KB |
Number of queries: 9 |
3 |
Correct |
17 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
15 ms |
352 KB |
Number of queries: 9 |