#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
#define mp make_pair
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair < int, int >
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef long long ll;
typedef long double ld;
const int maxn = 2055;
vector < int > g[maxn], islands;
int verts[maxn], timer;
bool used[maxn];
void dfs(int v) {
used[v] = true;
verts[timer++] = v;
for (int j = 0; j < sz(g[v]); j++) {
int to = g[v][j];
if (!used[to])
dfs(to);
}
}
bool prov(int max_ind) {
islands.clear();
for (int i = 0; i <= max_ind; i++)
islands.pb(verts[i] + 1);
return query(islands);
}
int bin_search() {
int l = -1, r = timer - 1;
while (r - l > 1) {
int m = (l + r) / 2;
if (prov(m))
r = m;
else
l = m;
}
return verts[r] + 1;
}
int findEgg(int n, vector < pii > bridges) {
for (int i = 0; i < n; i++) {
g[i].clear();
used[i] = false;
}
for (int i = 0; i < sz(bridges); i++) {
int u = bridges[i].fs, v = bridges[i].sc;
u--;
v--;
g[u].pb(v);
g[v].pb(u);
}
timer = 0;
dfs(0);
return bin_search();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
244 KB |
Number of queries: 4 |
2 |
Correct |
6 ms |
376 KB |
Number of queries: 4 |
3 |
Correct |
6 ms |
376 KB |
Number of queries: 4 |
4 |
Correct |
6 ms |
376 KB |
Number of queries: 4 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
300 KB |
Number of queries: 8 |
2 |
Correct |
20 ms |
380 KB |
Number of queries: 9 |
3 |
Correct |
22 ms |
300 KB |
Number of queries: 9 |
4 |
Correct |
26 ms |
376 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
376 KB |
Number of queries: 9 |
2 |
Correct |
19 ms |
300 KB |
Number of queries: 9 |
3 |
Correct |
22 ms |
280 KB |
Number of queries: 9 |
4 |
Correct |
38 ms |
376 KB |
Number of queries: 9 |