#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
using idata = vector<int>;
using graph = vector<idata>;
using ipair = pair<int, int>;
using ipdata = vector<ipair>;
graph roads;
idata tour;
void dfs (int node, int parent) {
tour.push_back(node);
for (int next : roads[node]) if (next != parent)
dfs(next, node);
}
int query (int size) {
idata query_tour(size);
for (int i = 0; i < size; i ++)
query_tour[i] = tour[i];
return query(query_tour);
}
int result () {
int a = 0;
int b = tour.size();
while (b - a > 1) {
int c = (a + b) >> 1;
if (query(c)) b = c;
else a = c;
}
return tour[b - 1];
}
int findEgg (int N, ipdata bridges)
{
roads.clear ();
roads.resize(N + 1);
tour .clear ();
for (ipair bridge : bridges) {
roads[bridge.first ].push_back(bridge.second);
roads[bridge.second].push_back(bridge.first );
}
dfs(1, -1);
return result();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
4 |
Correct |
2 ms |
208 KB |
Number of queries: 4 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
360 KB |
Number of queries: 8 |
2 |
Correct |
13 ms |
348 KB |
Number of queries: 9 |
3 |
Correct |
20 ms |
348 KB |
Number of queries: 9 |
4 |
Correct |
17 ms |
368 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
376 KB |
Number of queries: 9 |
2 |
Correct |
19 ms |
336 KB |
Number of queries: 9 |
3 |
Correct |
24 ms |
356 KB |
Number of queries: 9 |
4 |
Correct |
17 ms |
336 KB |
Number of queries: 9 |