#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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
208 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Number of queries: 8 |
2 |
Correct |
8 ms |
344 KB |
Number of queries: 9 |
3 |
Correct |
21 ms |
352 KB |
Number of queries: 9 |
4 |
Correct |
13 ms |
488 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
480 KB |
Number of queries: 9 |
2 |
Correct |
11 ms |
360 KB |
Number of queries: 9 |
3 |
Correct |
14 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
19 ms |
356 KB |
Number of queries: 9 |