#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
vector <vector<int>> G;
vector <int> order;
void dfs(int v, int p) {
order.push_back(v);
for (auto it : G[v]) {
if (it == p) continue;
dfs(it, v);
}
}
int findEgg(int n, vector < pair < int, int > > bridges) {
order.clear();
G.clear();
G.resize(n + 1);
for (auto &it : bridges) {
G[it.first].push_back(it.second);
G[it.second].push_back(it.first);
}
dfs(1, -1);
int ans = n - 1;
int l = 0, r = n - 2;
while (l <= r) {
vector <int> w;
int mid = (l + r) / 2;
for (int i = 0; i <= mid; i++) {
w.push_back(order[i]);
}
if (query(w)) {
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
return order[ans];
}
# |
결과 |
실행 시간 |
메모리 |
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 |
3 ms |
344 KB |
Number of queries: 8 |
2 |
Correct |
11 ms |
344 KB |
Number of queries: 9 |
3 |
Correct |
10 ms |
344 KB |
Number of queries: 9 |
4 |
Correct |
9 ms |
344 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Number of queries: 9 |
2 |
Correct |
9 ms |
344 KB |
Number of queries: 9 |
3 |
Correct |
12 ms |
600 KB |
Number of queries: 9 |
4 |
Correct |
9 ms |
344 KB |
Number of queries: 9 |