답안 #867400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867400 2023-10-28T10:32:27 Z lalig777 Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
13 ms 1244 KB
#include "grader.h"
#include <iostream>
#include <vector>
using namespace std;

void dfs_function(int N, vector<vector<int>>&listaAdy, vector<int>&dfs, int i, int padre){
    dfs.push_back(i);
    for (int conexiones: listaAdy[i]){
        if (conexiones!=padre) dfs_function(N, listaAdy, dfs, conexiones, i);
    }return;
}

int findEgg(int N, vector<pair<int,int>>bridges){
    vector<int>islands;
    vector<vector<int>>listaAdy(N);
    for (int i=0; i<N-1; i++){
        int a=bridges[i].first-1;
        int b=bridges[i].second-1;
        listaAdy[a].push_back(b);
        listaAdy[b].push_back(a);
    }vector<int>dfs;
    dfs_function(N, listaAdy, dfs, 0, -1);
    int l=0, r=N-1, m;
    while (l<r){
        m=(r-l)/2+l;
        islands.clear();
        for (int i=0; i<=m; i++) islands.push_back(dfs[i]+1);
        if (query(islands)==1) r=m;
        else l=m+1;
    }return dfs[l]+1;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 1 ms 344 KB Number of queries: 4
4 Correct 1 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 980 KB Number of queries: 8
2 Correct 8 ms 984 KB Number of queries: 9
3 Correct 12 ms 728 KB Number of queries: 9
4 Correct 11 ms 748 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1024 KB Number of queries: 9
2 Correct 11 ms 1244 KB Number of queries: 9
3 Correct 12 ms 736 KB Number of queries: 9
4 Correct 12 ms 988 KB Number of queries: 9