답안 #660272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660272 2022-11-21T12:02:46 Z BlancaHM Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
21 ms 584 KB
#include <bits/stdc++.h>
#include "grader.h"
 
using namespace std;
 
vector<int> order;
vector<vector<int>> listaAdy;
 
void dfs(int nodo, int padre){
    order.push_back(nodo);
    for(int vecino: listaAdy[nodo]){
        if(vecino == padre) continue;
        dfs(vecino, nodo);
    }
}
 
int findEgg (int N, vector < pair < int, int > > bridges)
{
    listaAdy = vector<vector<int>>(N+1);
    for(pair<int, int> bridge: bridges){
        listaAdy[bridge.second].push_back(bridge.first);
        listaAdy[bridge.first].push_back(bridge.second);
    }
    dfs(1, -1);
    int ans = N;
    int lo = 1; int hi = N-1;
    vector<int> ask((N)/2);
    for(int i = 0; i < (N)/2; ++i) ask[i] = order[i];
    while(hi >= lo){
        int mid = (hi + lo)/2;
        while(ask.size() < (mid)){
            ask.push_back(order[ask.size()]);
        }
        while(ask.size() > (mid)) ask.pop_back();
        if(query(ask)){
            hi = mid-1;
            ans = mid;
        }
        else{
            lo = mid+1;
        }
    }
    return order[ans-1];
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:31:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |         while(ask.size() < (mid)){
      |               ~~~~~~~~~~~^~~~~~~
eastereggs.cpp:34:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         while(ask.size() > (mid)) ask.pop_back();
      |               ~~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Number of queries: 4
2 Correct 1 ms 304 KB Number of queries: 4
3 Correct 1 ms 356 KB Number of queries: 4
4 Correct 1 ms 208 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 368 KB Number of queries: 8
2 Correct 11 ms 456 KB Number of queries: 9
3 Correct 17 ms 452 KB Number of queries: 9
4 Correct 15 ms 472 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 584 KB Number of queries: 9
2 Correct 21 ms 552 KB Number of queries: 9
3 Correct 15 ms 440 KB Number of queries: 9
4 Correct 14 ms 468 KB Number of queries: 9