Submission #525622

# Submission time Handle Problem Language Result Execution time Memory
525622 2022-02-12T06:57:43 Z tudor Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
20 ms 356 KB
#include <iostream>
#include <vector>
#include "grader.h"
using namespace std;
const int nmax = 512;
int n;
vector < pair < int, int > > bridges;
vector < int > g[nmax + 1];
vector < int > ord;
vector < int > q;
void dfs ( int node, int parent ) {
    ord.push_back ( node );
    for ( int i = 0; i < g[node].size (); i++ )
        if ( g[node][i] != parent )
            dfs ( g[node][i], node );
}
/**
int query ( vector < int > islands ) {
    int r;
    cin >> r;
    return r;
} **/

int findEgg ( int n, vector < pair < int, int > > bridges ) {
    ord.clear ();
    for ( int i = 1; i <= n; i++ )
        g[i].clear ();
    for ( int i = 0; i < n - 1; i++ ) {
        g[bridges[i].first].push_back ( bridges[i].second );
        g[bridges[i].second].push_back ( bridges[i].first );
    }
    dfs ( 1, 0 );
    int st = 0, dr = n - 2, mij, poz = n - 1;
    while ( st <= dr ) {
        int mij = st + ( dr - st ) / 2;
        q.clear ();
        for ( int i = 0; i <= mij; i++ )
            q.push_back ( ord[i] );
        if ( query ( q ) == 1 )
            dr = mij - 1, poz = mij;
        else
            st = mij + 1;
    }
    return ord[poz];
}
/*
int main() {
    cin >> n;
    bridges.resize ( n );
    for ( int i = 0; i < n - 1; i++ )
        cin >> bridges[i].first >> bridges[i].second;
     cout << findEgg ( n, bridges );

    return 0;
} */

Compilation message

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:13:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for ( int i = 0; i < g[node].size (); i++ )
      |                      ~~^~~~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:33:29: warning: unused variable 'mij' [-Wunused-variable]
   33 |     int st = 0, dr = n - 2, mij, poz = n - 1;
      |                             ^~~
# 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 5 ms 336 KB Number of queries: 8
2 Correct 12 ms 344 KB Number of queries: 9
3 Correct 18 ms 348 KB Number of queries: 9
4 Correct 20 ms 340 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 16 ms 356 KB Number of queries: 9
2 Correct 17 ms 336 KB Number of queries: 9
3 Correct 16 ms 340 KB Number of queries: 9
4 Correct 17 ms 348 KB Number of queries: 9