답안 #485954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485954 2021-11-09T20:05:21 Z Neacsu_Mihai Easter Eggs (info1cup17_eastereggs) C++14
87 / 100
17 ms 364 KB
#include <iostream>
#include <fstream>
#include <vector>
#include "grader.h"

#define NMAX 512

using namespace std;

//ifstream fin ("test.in");
//ofstream fout ("test.out");

//int ou;
//vector < pair< int, int > > bridges;
vector < int > G[NMAX + 1];
vector < int > vecDFS;

void DFS(int node, int tata){
    vecDFS.push_back(node);

    for(auto it : G[node]){
        if(it != tata){
            DFS(it, node);
        }
    }


}

/*
int query(vector <int> islands){
    for(int i = 0; i < islands.size(); i++){
        if(islands[i] == ou){
            return 1;
        }
    }
    return 0;
}
*/

int findEgg(int N, vector <pair <int, int> > bridges){
    vecDFS.clear();

    for(int i = 1; i <= N; i++){
        G[i].clear();
    }

    for(int i = 0; i < bridges.size(); i++){
        int A = bridges[i].first;
        int B = bridges[i].second;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    DFS(1, 1);

    int lo = -1;
    int hi = N; //adica vecDFS.size();

    while(hi - lo > 1){
        int mid = lo + (hi - lo) / 2;

        if( query( vector<int>(vecDFS.begin(), vecDFS.begin() + mid + 1) ) == 1){
            hi = mid;
        }
        else {
            lo = mid;
        }
    }

    return vecDFS[hi];
}

/*
int main()
{
    int N;
    fin >> N;
    fin >> ou;

    for(int i = 1; i <= N - 1; i++){
        int a, b;
        fin >> a >> b;
        bridges.push_back({a, b});
    }

    fout << findEgg(N, bridges);
}
*/

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i = 0; i < bridges.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 200 KB Number of queries: 5
2 Partially correct 1 ms 200 KB Number of queries: 5
3 Partially correct 1 ms 200 KB Number of queries: 5
4 Partially correct 1 ms 200 KB Number of queries: 5
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 328 KB Number of queries: 9
2 Correct 11 ms 340 KB Number of queries: 9
3 Correct 16 ms 348 KB Number of queries: 9
4 Correct 17 ms 348 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Partially correct 16 ms 364 KB Number of queries: 10
2 Correct 12 ms 328 KB Number of queries: 9
3 Partially correct 13 ms 348 KB Number of queries: 10
4 Partially correct 14 ms 344 KB Number of queries: 10