Submission #588581

#TimeUsernameProblemLanguageResultExecution timeMemory
588581IwanttobreakfreeEaster Eggs (info1cup17_eastereggs)C++17
0 / 100
2 ms592 KiB
#include <iostream> #include <vector> #include <set> #include "grader.h" using namespace std; void dfs(int a,int par,vector<vector<int>>& g,vector<int>& pos,int& cnt,set<int>& q){ if(cnt){ q.insert(a+1); if(pos[a])cnt--; }else return; for(int x:g[a]){ if(x==par)continue; dfs(x,a,g,pos,cnt,q); if(!cnt)return; } } int findEgg (int n,vector<pair<int,int>> bridges){ vector<vector<int>> g(n,vector<int>()); vector<int> pos(n,1); for(auto x:bridges){ x.first--;x.second--; g[x.first].push_back(x.second); g[x.second].push_back(x.first); } int l=1,r=n; while(l<r){ int mid=(r+l)/2; set<int> s; dfs(0,0,g,pos,mid,s); vector<int> q; for(auto x:s)q.push_back(x); bool egg=query(q); int y=0; for(int i=0;i<n;i++){ if(pos[i]){ if(egg&&s.find(i+1)==s.end())pos[i]=0; if(!egg&&s.find(i+1)!=s.end())pos[i]=0; } if(pos[i])y++; } r=y; } for(int i=0;i<n;i++)if(pos[i])return i; return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...