#include <bits/stdc++.h>
#ifndef BALBIT
#include "grader.h"
#endif
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBITs
namespace {
const int maxn = 600;
vector<int> g[maxn];
bool maybe[maxn];
int need = 0;
vector<int> ord;
void dfs(int v, int p) {
ord.pb(v);
for (int u: g[v]) {
if (u != p) {
dfs(u,v);
}
}
}
}
#ifdef BALBIT
bool query(vector<int> rr) {
for (int x : rr) cout<<x<<' ';
cout<<endl;
bug("??");
int y; cin>>y;
return y;
}
#endif // BALBIT
int findEgg (int n, vector < pair < int, int > > bridges)
{
// return 1;
// if (query({n})) return 1;
// return n;
REP1(i,n) g[i].clear();
for (pii p: bridges) {
g[p.f].pb(p.s);
g[p.s].pb(p.f);
}
fill(maybe, maybe+n+1,1);
ord.clear();
dfs(1, -1);
// return 1;
int left = n;
int quers = 0;
while (left > 1) {
need=left/2;
vector<int> tk;
vector<int> tkg;
REP(i,n) {
int v = ord[i];
if (maybe[v]) {
--need;
tkg.pb(v);
}
tk.pb(v);
if (need == 0) break;
}
sort(ALL(tk));
if (query(tk)) {
left = left/2;
fill(maybe, maybe+n+1, 0);
for (int y : tkg) maybe[y] = 1;
}else{
left = left - left/2;
for (int y : tk) maybe[y] = 0;
}
// ++quers;
// if(quers > 10) while (1);
}
// while (1);
// return 1;
REP(i,n) {
int v = ord[i];
if (maybe[v]) {
// if (!query({v})) while(1);
return v;
}
}
while (1);
return 0;
// assert(0);
}
#ifdef BALBIT
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
bug(findEgg(5, {{1, 2}, {1, 3}, {2,4}, {4,5}}));
}
#endif
Compilation message
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:72:9: warning: unused variable 'quers' [-Wunused-variable]
72 | int quers = 0;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
244 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
348 KB |
Number of queries: 8 |
2 |
Correct |
17 ms |
328 KB |
Number of queries: 9 |
3 |
Correct |
23 ms |
344 KB |
Number of queries: 9 |
4 |
Correct |
28 ms |
456 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
328 KB |
Number of queries: 9 |
2 |
Correct |
22 ms |
448 KB |
Number of queries: 9 |
3 |
Correct |
26 ms |
360 KB |
Number of queries: 9 |
4 |
Correct |
25 ms |
364 KB |
Number of queries: 9 |