# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
895611 | 2023-12-30T11:33:22 Z | maxFedorchuk | Easter Eggs (info1cup17_eastereggs) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; const long long MX=600; vector < int > mas[MX]; int pos1[MX]; int pos2[MX]; /* int query(vector < int > islands) { for(auto u:islands) { cout<<u<<" "; } cout<<"\n"; int ans; cin>>ans; return ans; } */ vector < int > chk(int k1,int n) { for(int i=1;i<=n;i++) { pos2[i]=0; } queue < int > q; q.push(1); int zlk1=k1; while(zlk1!=0) { int zar=q.front(); q.pop(); pos2[zar]=1; zlk1-=pos1[zar]; for(auto vr:mas[zar]) { if(!pos2[vr]) { q.push(vr); } } } vector < int > zap; for(int i=1;i<=n;i++) { if(pos2[i]) { zap.push_back(i); } } return zap; } int findEgg(int n, vector < pair < int, int > > bridges) { for(auto [a,b]:bridges) { mas[a].push_back(b); mas[b].push_back(a); } for(int i=1;i<=n;i++) { pos1[i]=1; } int k1=n; while(k1!=1) { int nwk1=k1/2; if(query(chk(nwk1,n))) { for(int i=1;i<=n;i++) { if(pos1[i] && pos2[i]) { pos1[i]=1; } else { pos1[i]=0; } } k1=nwk1; } else { for(int i=1;i<=n;i++) { if(pos1[i] && !pos2[i]) { pos1[i]=1; } else { pos1[i]=0; } } k1-=nwk1; } } for(int i=1;i<=n;i++) { if(pos1[i]==1) { return i; } } } /* int main() { //cin.tie(0); //ios_base::sync_with_stdio(0); int n=5; vector < pair < int , int > > bridges(n-1); bridges[0]=make_pair(1,2); bridges[1]=make_pair(1,3); bridges[2]=make_pair(2,4); bridges[3]=make_pair(4,5); cout<<findEgg(n,bridges)<<"\n"; return 0; } */