Submission #660274

# Submission time Handle Problem Language Result Execution time Memory
660274 2022-11-21T12:28:05 Z a_aguilo Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
22 ms 588 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;
    while(hi >= lo){
        int mid = lo + (hi - lo)/2;
        vector<int> ask(mid);
        for(int i = 0; i < mid; ++i) ask[i] = order[i];
        if(query(ask)){
            hi = mid-1;
            ans = mid;
        }
        else{
            lo = mid+1;
        }
    }
    return order[ans-1];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Number of queries: 4
2 Correct 1 ms 208 KB Number of queries: 4
3 Correct 1 ms 208 KB Number of queries: 4
4 Correct 1 ms 208 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 5 ms 400 KB Number of queries: 8
2 Correct 12 ms 452 KB Number of queries: 9
3 Correct 18 ms 536 KB Number of queries: 9
4 Correct 19 ms 476 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 21 ms 588 KB Number of queries: 9
2 Correct 16 ms 540 KB Number of queries: 9
3 Correct 22 ms 544 KB Number of queries: 9
4 Correct 15 ms 496 KB Number of queries: 9