#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 = 1;
void reseteaza()
{
for(int i = 1; i <= 512; i++)
{
muc[i].clear();
q[i] = 0;
order[i] = 0;
cnt = 1;
visited[i] = false;
}
qv.clear();
}
void bfs()
{
int st = 1, dr = 1;
q[1] = 1, order[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];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |