#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
vector<int> G[600];
int renumbered[600];
int inverse_renumber[600];
void renumber_dfs(int node,int father,int &val){
renumbered[node] = val;
inverse_renumber[val] = node;
for(auto it:G[node]){
if(it != father){
renumber_dfs(it,node,++val);
}
}
}
vector<int> nodes;
bool ok(int le,int ri){
nodes.clear();
for(int i = le;i <= ri;i++){
nodes.push_back(inverse_renumber[i]);
}
return query(nodes);
}
int findEgg (int N, vector < pair < int, int > > bridges){
for(int i = 1;i <= N;i++){
G[i].clear();
}
for(auto it:bridges){
G[it.first].push_back(it.second);
G[it.second].push_back(it.first);
}
int start = 1;
renumber_dfs(1,0,start);
int lo = 1,hi = N;
while(hi - lo > 0){
int mid = (lo + hi) / 2;
if(ok(1,mid)){
hi = mid;
}
else{
lo = mid + 1;
}
}
return inverse_renumber[lo];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Number of queries: 4 |
2 |
Correct |
4 ms |
308 KB |
Number of queries: 4 |
3 |
Correct |
3 ms |
472 KB |
Number of queries: 4 |
4 |
Correct |
2 ms |
472 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
548 KB |
Number of queries: 8 |
2 |
Correct |
14 ms |
548 KB |
Number of queries: 9 |
3 |
Correct |
24 ms |
548 KB |
Number of queries: 9 |
4 |
Correct |
27 ms |
548 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
568 KB |
Number of queries: 9 |
2 |
Correct |
28 ms |
572 KB |
Number of queries: 9 |
3 |
Correct |
23 ms |
576 KB |
Number of queries: 9 |
4 |
Correct |
19 ms |
700 KB |
Number of queries: 9 |