#include <cstring>
#include <vector>
#include <deque>
#include "grader.h"
#define MAX 522
using namespace std;
int vf[MAX];
vector<int> v[MAX];
int n,x,y;
vector<int> bfs(int N, vector< pair<int, int> > bridges){
memset(vf, 0, sizeof(vf));
for(int i = 0; i < MAX; i++){
v[i].clear();
}
for(auto [x, y]: bridges){
v[x].push_back(y);
v[y].push_back(x);
}
deque<int> coada;
vf[1] = 1;
int maxi = 0;
coada.push_back(1);
while(!coada.empty()){
int nod = coada.back();
for(auto vecin: v[nod]){
if(vf[vecin] == 0){
vf[vecin] = 1+vf[nod];
maxi = max(maxi, vf[vecin]);
coada.push_front(vecin);
}
}
coada.pop_back();
}
vector<int> ans;
for(int i = 1; i <= maxi; i++){
for(int j = 0; j <= N; j++){
if(vf[j] == i){
ans.push_back(j);
}
}
}
return ans;
}
int findEgg(int N, vector< pair<int, int> > bridges){
vector<int> parcurgere = bfs(N, bridges);
/// 0 0 0 0 1 1 1 1
/// ^
int st = 0, dr = parcurgere.size()-2;
int ans = parcurgere.back();
while(st <= dr){
int mid = (st+dr)/2;
vector<int> partit;
for(int i = 0; i <= mid; i++){
partit.push_back(parcurgere[i]);
}
if(query(partit)){
ans = parcurgere[mid];
dr = mid-1;
}else{
st = mid+1;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
212 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
216 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
356 KB |
Number of queries: 8 |
2 |
Correct |
11 ms |
348 KB |
Number of queries: 9 |
3 |
Correct |
26 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
22 ms |
352 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
348 KB |
Number of queries: 9 |
2 |
Correct |
18 ms |
348 KB |
Number of queries: 9 |
3 |
Correct |
19 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
20 ms |
336 KB |
Number of queries: 9 |