# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
864279 | 2023-10-22T09:58:30 Z | gutzzy | Easter Eggs (info1cup17_eastereggs) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "grader.h" using namespace std; int fingEgg(int n, vector<pair<int, int>>bridges){ // vector 1D de todas las islas vector<vector<int>> lst(n,vector<int>()); for(auto b:bridges){ lst[b.first-1].push_back(b.second-1); lst[b.second-1].push_back(b.first-1); } vector<int> islands; int isl=0; while((int) lst[isl].size()!=1) isl++; // busco un extremo islands.push_back(isl); int l_isl = isl; isl = lst[l_isl][0]; islands.push_back(isl); while((int) islands.size() != n){ int t = isl; if(lst[isl][0]==l_isl) isl = lst[isl][1]; else isl = lst[isl][1]; l_isl = t; islands.push_back(isl); } // binary search int l = 0; int r = n-1; while(l<=r){ int m = (l+r)/2; bool egg = query({islands.begin(),islands.begin()+m}); if(egg) r = m-1; else l = m+1; } return l; }