답안 #865004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865004 2023-10-23T22:43:24 Z gutzzy Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
13 ms 1276 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;

vector<int> islands;
vector<bool> visited;
vector<vector<int>> lst;

void dfs(int nodo){
    visited[nodo] = true;
    islands.push_back(nodo);
    for(int vecino:lst[nodo]){
        if(!visited[vecino]) dfs(vecino);
    }
}

int findEgg(int n, vector<pair<int, int>>bridges){
    // vector 1D de todas las islas
    lst = vector<vector<int>>(n);
    
    for(auto b:bridges){
        lst[b.first-1].push_back(b.second-1);
        lst[b.second-1].push_back(b.first-1);
    }
    
    visited = vector<bool>(n,false);
    islands.clear();
    
    dfs(0);
    
    for(int i=0;i<n;i++) islands[i]++;
    
    // binary search
    
    int l = 0;
    int r = n-1;
    while(l<r){
        int m = (l+r)/2;
        //cout << l << " " << r << " " << m << endl;
        bool egg = query({islands.begin(),islands.begin()+m+1});
        if(egg) r = m;
        else l = m+1;
    }
    return islands[l];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 0 ms 344 KB Number of queries: 4
4 Correct 0 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 728 KB Number of queries: 8
2 Correct 8 ms 472 KB Number of queries: 9
3 Correct 12 ms 492 KB Number of queries: 9
4 Correct 11 ms 736 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1276 KB Number of queries: 9
2 Correct 10 ms 476 KB Number of queries: 9
3 Correct 12 ms 748 KB Number of queries: 9
4 Correct 11 ms 748 KB Number of queries: 9