Submission #659623

# Submission time Handle Problem Language Result Execution time Memory
659623 2022-11-18T19:05:40 Z a_aguilo Easter Eggs (info1cup17_eastereggs) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

int sol;

int query(vector<int>& V){
    for(int n: V){
        if(n == sol) return 1;
    }
    return 0;
}

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);
    order = vector<int>();
    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 = 0;
    int lo = 0; int hi = N-1;
    vector<int> ask((N-1)/2);
    while(hi >= lo){
        int mid = lo + (hi - lo);
        while(ask.size() < mid){
            ask.push_back(order[ask.size()]);
        }
        while(ask.size() > mid) ask.pop_back();
        if(query(ask)){
            hi = mid-1;
        }
        else{
            ans = mid;
            lo = mid+1;
        }
    }
    return order[ans];
}


int main(){
    int n;
    cin >> n;
    cin >> sol;
    vector<pair<int, int>> connections(n-1);
    for(int i = 0; i < n-1; ++i) cin >> connections[i].first >> connections[i].second;
    cout << findEgg(n, connections) << endl;
    return 0;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:38:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         while(ask.size() < mid){
      |               ~~~~~~~~~~~^~~~~
eastereggs.cpp:41:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |         while(ask.size() > mid) ask.pop_back();
      |               ~~~~~~~~~~~^~~~~
/usr/bin/ld: /tmp/cc45aC2H.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccLJnhkI.o:eastereggs.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status