#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
vector<int> islands;
vector<bool> visited;
vector<vector<int>> lst;
void dfs(int nodo){
visited[nodo] = true;
islands.push_back(nodo);
for(int vecino:lst[nodo]){
if(!visited[vecino]) dfs(vecino);
}
}
int findEgg(int n, vector<pair<int, int>>bridges){
// vector 1D de todas las islas
lst = vector<vector<int>>(n);
for(auto b:bridges){
lst[b.first-1].push_back(b.second-1);
lst[b.second-1].push_back(b.first-1);
}
visited = vector<bool>(n,false);
islands.clear();
dfs(0);
for(int i=0;i<n;i++) islands[i]++;
// binary search
int l = 0;
int r = n-1;
while(l<r){
int m = (l+r)/2;
//cout << l << " " << r << " " << m << endl;
vector<int> q(m+1);
for (int i = 0; i <= m; ++i) {
q[i] = islands[i];
}
if(query(q)) r = m;
else l = m+1;
}
return islands[l];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
436 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
432 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
436 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
432 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
472 KB |
Number of queries: 8 |
2 |
Correct |
9 ms |
980 KB |
Number of queries: 9 |
3 |
Correct |
12 ms |
724 KB |
Number of queries: 9 |
4 |
Correct |
12 ms |
740 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1272 KB |
Number of queries: 9 |
2 |
Correct |
11 ms |
1252 KB |
Number of queries: 9 |
3 |
Correct |
12 ms |
1272 KB |
Number of queries: 9 |
4 |
Correct |
12 ms |
1008 KB |
Number of queries: 9 |