#include "bits/stdc++.h"
#include "grader.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
using ll = long long;
const int mod = 1e9+7;
void dfs(int u, int p, vector<vector<int>> &adj, vector<int> &o) {
o.push_back(u);
for (int v : adj[u])
if (v != p)
dfs(v, u, adj, o);
}
int findEgg(int n, vector<pair<int, int>> bridges) {
vector<vector<int>> adj(n+1);
vector<int> o;
for (auto [u, v] : bridges) {
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, -1, adj, o);
int l = 0, r = n-1;
auto chk = [&] (int m) -> bool {
vector<int> v(o.begin(), o.begin() + m + 1);
/* for (int x : v)
cout << x << " ";
cout << '\n';
*/ return query(v);
};
while (l < r) {
int m = (l + r) / 2;
// cout << "m : " << m << '\n';
if (chk(m)) {
// cerr << "true\n";
r = m;
} else {
// cout << "false\n";
l = m+1;
}
}
// cout << r << " " << o[r] << '\n';
return o[r];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Number of queries: 4 |
2 |
Correct |
2 ms |
200 KB |
Number of queries: 4 |
3 |
Correct |
2 ms |
200 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
340 KB |
Number of queries: 8 |
2 |
Correct |
15 ms |
348 KB |
Number of queries: 9 |
3 |
Correct |
22 ms |
356 KB |
Number of queries: 9 |
4 |
Correct |
20 ms |
352 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
496 KB |
Number of queries: 9 |
2 |
Correct |
20 ms |
364 KB |
Number of queries: 9 |
3 |
Correct |
25 ms |
456 KB |
Number of queries: 9 |
4 |
Correct |
25 ms |
348 KB |
Number of queries: 9 |