#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
using pii = pair<int, int>;
bool my_query(const set<int> &s) {
if (s.empty()) return 0;
vector<int> v;
for (auto &it : s)
v.push_back(it);
return query(v);
}
int findEgg(int n, vector<pii> bridges) {
vector<vector<int>> g(n + 1);
vector<bool> vis(n + 1);
vector<int> euler;
vector<int> in;
for (auto [ x, y ] : bridges) {
g[x].push_back(y);
g[y].push_back(x);
}
function<void(int)> dfs = [&](int x) {
vis[x] = true;
in.push_back(int(euler.size()));
euler.push_back(x);
for (auto u : g[x]) {
if (!vis[u]) {
dfs(u);
euler.push_back(x);
}
}
};
dfs(1);
function<bool(int)> check = [&](int mid) {
set<int> s;
for (int i = 0; i <= in[mid]; i++)
s.insert(euler[i]);
return my_query(s);
};
int mask = 0;
for (int i = log2(in.size()); i >= 0; i--) {
mask |= 1 << i;
if (mask >= int(in.size()) || check(mask - 1)) mask ^= 1 << i;
}
return euler[in[mask]];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
344 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
344 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
344 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
732 KB |
Number of queries: 8 |
2 |
Correct |
15 ms |
1016 KB |
Number of queries: 9 |
3 |
Correct |
23 ms |
744 KB |
Number of queries: 9 |
4 |
Correct |
22 ms |
772 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
804 KB |
Number of queries: 9 |
2 |
Correct |
19 ms |
520 KB |
Number of queries: 9 |
3 |
Correct |
22 ms |
1016 KB |
Number of queries: 9 |
4 |
Correct |
20 ms |
1020 KB |
Number of queries: 9 |