Submission #687456

# Submission time Handle Problem Language Result Execution time Memory
687456 2023-01-26T12:18:34 Z heeheeheehaaw Easter Eggs (info1cup17_eastereggs) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include "grader.h"

using namespace std;

vector<int> qv;
vector<int> muc[512 + 5];
bool visited[512 + 5];
int q[512 + 5], order[512 + 5], cnt = 1;

int query(vector<int> marog)
{
    for(int i = 0; i < marog.size(); i++)
        cout<<marog[i]<<" ";
    cout<<'\n';
    int cv;
    cin>>cv;
    return cv;
}

void reseteaza()
{
    for(int i = 1; i <= 512; i++)
    {
        muc[i].clear();
        q[i] = 0;
        order[i] = 0;
        cnt = 1;
        visited[i] = false;
    }
    qv.clear();

}

void bfs()
{
    int st = 1, dr = 1;
    q[1] = 1, order[1] = 1, visited[1] = true;
    while(st <= dr)
    {
        int nod = q[st];
        st++, cnt++;
        order[cnt] = nod;
        for(auto it: muc[nod])
            if(!visited[it])
            {
                dr++, q[dr] = it;
                visited[it] = true;
            }
    }
    return;
}

int findEgg(int N, vector<pair<int, int>> bridges)
{
    reseteaza();
    for(auto it: bridges)
    {
        muc[it.first].push_back(it.second);
        muc[it.second].push_back(it.first);
    }
    bfs();
    int st = 1, dr = cnt;
    while(st <= dr)
    {
        int mij = (st + dr) / 2;
        if(st == dr)
            return order[st];
        qv.empty();
        for(int i = 1; i <= mij; i++)
            qv.push_back(order[i]);
        int val = query(qv);
        if(val == 1)
            dr = mij;
        else
            st = mij + 1;
    }
    return order[st];
}

Compilation message

eastereggs.cpp: In function 'int query(std::vector<int>)':
eastereggs.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i = 0; i < marog.size(); i++)
      |                    ~~^~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:70:17: warning: ignoring return value of 'bool std::vector<_Tp, _Alloc>::empty() const [with _Tp = int; _Alloc = std::allocator<int>]', declared with attribute 'nodiscard' [-Wunused-result]
   70 |         qv.empty();
      |         ~~~~~~~~^~
In file included from /usr/include/c++/10/vector:67,
                 from eastereggs.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:1007:7: note: declared here
 1007 |       empty() const _GLIBCXX_NOEXCEPT
      |       ^~~~~
/usr/bin/ld: /tmp/ccP0GOuG.o: in function `query(std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x0): multiple definition of `query(std::vector<int, std::allocator<int> >)'; /tmp/ccemwYEH.o:eastereggs.cpp:(.text+0x50): first defined here
collect2: error: ld returned 1 exit status