#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;
while (a < b)
{
size_t mid = (a + b) / 2;
if (query(vector<int>(preorder.begin(), preorder.begin() + mid)))
b = mid;
else
a = mid + 1;
}
return preorder[a - 1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Number of queries: 8 |
2 |
Correct |
12 ms |
336 KB |
Number of queries: 9 |
3 |
Correct |
16 ms |
352 KB |
Number of queries: 9 |
4 |
Correct |
13 ms |
360 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
336 KB |
Number of queries: 9 |
2 |
Correct |
14 ms |
336 KB |
Number of queries: 9 |
3 |
Runtime error |
6 ms |
464 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |