#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;
for (auto [ x, y ] : bridges) {
g[x].push_back(y);
g[y].push_back(x);
}
function<void(int)> dfs = [&](int x) {
vis[x] = true;
euler.push_back(x);
for (auto u : g[x]) {
if (!vis[u]) {
dfs(u);
euler.push_back(x);
}
}
};
dfs(1);
int cnt = 0;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
function<bool(int)> check = [&](int mid) {
if (++cnt == 4) return bool(abs(int(rng())) % 2);
set<int> s;
for (int i = 0; i < mid; i++)
s.insert(euler[i]);
return my_query(s);
};
int mask = 0;
for (int i = log2(euler.size()) - 1; i >= 0; i--) {
mask |= 1 << i;
if (mask >= int(euler.size()) - 1 || check(mask)) mask ^= 1 << i;
}
return euler[mask];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
436 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
484 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
532 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |