#include <stdio.h>
#include <vector>
#include "grader.h"
#define MAX_N 512
using namespace std;
int o;
int ord[MAX_N];
//vector <pair<int, int>> brdgs;
vector <int> m[MAX_N + 1];
vector <int> v;
/*int query( vector <int> insula ) {
int ans, i;
for ( i = 0; i < insula.size(); i++ )
printf( "%d ", insula[i] );
printf( "\n" );
scanf( "%d", &ans );
return ans;
}*/
void dfs( int nod, int p ) {
int i;
ord[o] = nod;
o++;
for ( i = 0; i < m[nod].size(); i++ ) {
if ( m[nod][i] != p )
dfs( m[nod][i], nod );
}
}
int findEgg( int n, vector <pair<int, int>> bridges ) {
int st, dr, mij, i;
for ( i = 0; i <= n; i++ )
m[i].clear();
for ( i = 0; i < n - 1; i++ ) {
m[bridges[i].first].push_back( bridges[i].second );
m[bridges[i].second].push_back( bridges[i].first );
}
o = 0;
dfs( 1, 0 );
st = -1;
dr = n - 1;
while ( dr - st > 1 ) {
mij = (st + dr) / 2;
v.clear();
for ( i = 0; i <= mij; i++ )
v.push_back( ord[i] );
if ( query( v ) )
dr = mij;
else
st = mij;
}
return ord[dr];
}
/*int main() {
int n, a, b, i;
scanf( "%d", &n );
for ( i = 0; i < n - 1; i++ ) {
scanf( "%d%d", &a, &b );
brdgs.push_back( make_pair( a, b ) );
}
printf( "%d", findEgg( n, brdgs ) );
return 0;
}*/
Compilation message
eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for ( i = 0; i < m[nod].size(); i++ ) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
336 KB |
Number of queries: 8 |
2 |
Correct |
13 ms |
328 KB |
Number of queries: 9 |
3 |
Correct |
20 ms |
328 KB |
Number of queries: 9 |
4 |
Correct |
18 ms |
344 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
364 KB |
Number of queries: 9 |
2 |
Correct |
17 ms |
340 KB |
Number of queries: 9 |
3 |
Correct |
18 ms |
352 KB |
Number of queries: 9 |
4 |
Correct |
19 ms |
328 KB |
Number of queries: 9 |