Submission #687467

#TimeUsernameProblemLanguageResultExecution timeMemory
687467heeheeheehaawEaster Eggs (info1cup17_eastereggs)C++17
100 / 100
21 ms488 KiB
#include <iostream> #include <vector> #include "grader.h" using namespace std; vector<int> qv; vector<int> muc[512 + 5]; bool visited[512 + 5]; int q[512 + 5], order[512 + 5], cnt = 0; /*int query(vector<int> marog) { for(int i = 0; i < marog.size(); i++) cout<<marog[i]<<" "; cout<<'\n'; int cv; cin>>cv; return cv; }*/ void reseteaza() { for(int i = 1; i <= 512; i++) { muc[i].clear(); q[i] = 0; order[i] = 0; cnt = 0; visited[i] = false; } qv.clear(); } void bfs() { int st = 1, dr = 1; q[1] = 1, visited[1] = true; while(st <= dr) { int nod = q[st]; st++, cnt++; order[cnt] = nod; for(auto it: muc[nod]) if(!visited[it]) { dr++, q[dr] = it; visited[it] = true; } } return; } int findEgg(int N, vector<pair<int, int>> bridges) { reseteaza(); for(auto it: bridges) { muc[it.first].push_back(it.second); muc[it.second].push_back(it.first); } bfs(); int st = 1, dr = cnt; while(st <= dr) { int mij = (st + dr) / 2; if(st == dr) return order[st]; qv.clear(); for(int i = 1; i <= mij; i++) qv.push_back(order[i]); int val = query(qv); if(val == 1) dr = mij; else st = mij + 1; } return order[st]; } vector<pair<int, int>> brid; /* int main() { int n; cin>>n; for(int i = 1; i < n; i++) { int a, b; cin>>a>>b; brid.push_back({a, b}); } cout<<findEgg(n, brid)<<'\n'; return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...