#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>> bridges;
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>> b ) {
int st, dr, mij, i;
for ( i = 0; i < n - 1; i++ ) {
m[b[i].first].push_back( b[i].second );
m[b[i].second].push_back( b[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 );
bridges.push_back( make_pair( a, b ) );
}
printf( "%d", findEgg( n, bridges ) );
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 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3061 ms |
328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3057 ms |
328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |