#include "grader.h"
#include <queue>
using namespace std;
int findEgg (int n, vector<pair<int,int>> bridges) {
vector<int> adj[n + 1];
bool visited[n + 1];
memset(visited, false, sizeof visited);
for (auto pair : bridges) {
int u = pair.first, v = pair.second;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<int> order;
queue<int> q; q.push(1);
visited[1] = true;
while (!q.empty()) {
int u = q.front();
q.pop();
order.push_back(u);
for (int v : adj[u]) if (!visited[v]) {
q.push(v);
visited[v] = true;
}
}
int l = 0, r = n-1;
while (r > l) {
int mid = (l+r)/2;
vector<int> myquery{};
for (int i = 0; i <= mid; i++) myquery.push_back(order[i]);
bool res = query(myquery) == 1;
// cout << "MY QUERY IS ";
// for (int u : myquery) cout << u << " ";
// cout << '\n';
if (res) r = mid;
else l = mid+1;
}
return order[l];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
344 KB |
Number of queries: 4 |
3 |
Correct |
0 ms |
344 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
344 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
472 KB |
Number of queries: 8 |
2 |
Correct |
6 ms |
344 KB |
Number of queries: 9 |
3 |
Correct |
12 ms |
752 KB |
Number of queries: 9 |
4 |
Correct |
8 ms |
344 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
344 KB |
Number of queries: 9 |
2 |
Correct |
12 ms |
344 KB |
Number of queries: 9 |
3 |
Correct |
8 ms |
600 KB |
Number of queries: 9 |
4 |
Correct |
9 ms |
504 KB |
Number of queries: 9 |