Submission #865002

# Submission time Handle Problem Language Result Execution time Memory
865002 2023-10-23T22:27:19 Z gutzzy Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
1 ms 516 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);
    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;
        vector<int> q(m+1);
        for (int i = 0; i <= m; ++i) {
            q[i] = islands[i];
        }
        if(query(q)) r = m;
        else l = m+1;
    }
    return islands[l];
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 440 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 516 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -