#include <bits/stdc++.h>
#include "grader.h"
#define MAX 512
using namespace std;
vector<int> adj[ MAX + 10 ];
vector<int> nodes;
void dfs( int node, int parent ) {
nodes.push_back( node );
for( auto next : adj[ node ] )
if( next != parent )
dfs( next, node );
}
int check( int pos ) {
vector<int> nodesQuery;
for( int i = 0; i < pos; i++ )
nodesQuery.push_back( nodes[ i ] );
return query( nodesQuery );
}
int findEgg( int N, vector<pair<int, int>> bridges ) {
for( int i = 1; i <= N; i++ )
adj[ i ].clear();
nodes.clear();
for( auto it : bridges ) {
adj[ it.first ].push_back( it.second );
adj[ it.second ].push_back( it.first );
}
dfs( 1, -1 );
int left = 0;
int right = nodes.size();
while( left + 1 < right ) {
int med = ( left + right ) / 2;
if( check( med ) == 1 )
right = med;
else left = med;
}
return nodes[ right - 1 ];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
7 ms |
464 KB |
Number of queries: 8 |
2 |
Correct |
14 ms |
464 KB |
Number of queries: 9 |
3 |
Correct |
21 ms |
340 KB |
Number of queries: 9 |
4 |
Correct |
15 ms |
336 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
372 KB |
Number of queries: 9 |
2 |
Correct |
16 ms |
472 KB |
Number of queries: 9 |
3 |
Correct |
15 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
17 ms |
344 KB |
Number of queries: 9 |