Submission #687330

# Submission time Handle Problem Language Result Execution time Memory
687330 2023-01-26T10:06:44 Z alexdd Easter Eggs (info1cup17_eastereggs) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;
int n;
vector<int> con[520];
vector<int> children[520];
vector<int> forniv[520];
int level[520];
bool visited[520];
int parent[520];
int rez=-1;
int mxmniv=0;
void dfs(int nod)
{
    visited[nod]=1;
    mxmniv = max(mxmniv, level[nod]);
    forniv[level[nod]].push_back(nod);
    for(auto adj:con[nod])
    {
        if(!visited[adj])
        {
            level[adj] = level[nod]+1;
            parent[adj]=nod;
            dfs(adj);
            for(int i=0;i<children[adj].size();i++)
                children[nod].push_back(children[adj][i]);
        }
    }
    children[nod].push_back(nod);
}
vector<int> aux;
void dfs2(int nod, int niv)
{
    visited[nod]=1;
    aux.push_back(nod);
    for(auto adj:con[nod])
    {
        if(!visited[adj] && level[adj]<=niv)
        {
            dfs2(adj);
        }
    }
}

bool verif_nivel(int niv)
{
    for(int i=1;i<=n;i++)
        visited[i]=0;
    aux.clear();
    dfs2(1,niv);
    return query(aux);
}

int find_nivel()
{
    int st,dr,mij;
    st=1;
    dr=mxmniv;
    while(st<=dr)
    {
        if(st==dr)
            return st;
        mij=(st+dr)/2;
        if(verif(mij))
            dr=mij;
        else
            st=mij+1;
    }
    return mij;
}

int fr[520];
bool verif_interval(int le, int ri, int niv)///returneaza 1 daca oul se afla in nodurile de pe forniv[niv][le..ri]
{
    aux.clear();
    for(int i=1;i<=n;i++)
        fr[i]=0;
    for(int i=le;i<=ri;i++)
    {
        int cur=forniv[niv][i];
        while(cur!=-1)
        {
            fr[cur]++;
            cur = parent[cur];
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(fr[i]>0)
            aux.push_back(i);
    }
    return query(aux);
}

int findEgg (int N, vector < pair < int, int > > bridges)
{
    n=N;
    for(int i=1;i<=N;i++)
    {
        visited[i]=0;
        con[i].clear();
        children[i].clear();
        forniv[i].clear();
    }
    rez=-1;
    mxmniv=0;
    for(auto x:bridges)
    {
        con[x.first].push_back(x.second);
        con[x.second].push_back(x.first);
    }
    level[1] = 1;
    parent[1]=-1;
    dfs(1);

    int niv = find_nivel();

    int st,dr,mij=0;
    st=0;
    dr=forniv[niv].size()-1;
    while(st<=dr)
    {
        if(st==dr)
            return forniv[st];
        mij=(st+dr)/2;
        if(verif_interval(st,mij,niv))
            dr=mij;
        else
            st=mij+1;
    }
    return forniv[mij];
}

Compilation message

eastereggs.cpp: In function 'void dfs(int)':
eastereggs.cpp:26:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             for(int i=0;i<children[adj].size();i++)
      |                         ~^~~~~~~~~~~~~~~~~~~~~
eastereggs.cpp: In function 'void dfs2(int, int)':
eastereggs.cpp:41:21: error: too few arguments to function 'void dfs2(int, int)'
   41 |             dfs2(adj);
      |                     ^
eastereggs.cpp:33:6: note: declared here
   33 | void dfs2(int nod, int niv)
      |      ^~~~
eastereggs.cpp: In function 'int find_nivel()':
eastereggs.cpp:65:12: error: 'verif' was not declared in this scope
   65 |         if(verif(mij))
      |            ^~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:125:29: error: cannot convert 'std::vector<int>' to 'int' in return
  125 |             return forniv[st];
      |                    ~~~~~~~~~^
      |                             |
      |                             std::vector<int>
eastereggs.cpp:132:22: error: cannot convert 'std::vector<int>' to 'int' in return
  132 |     return forniv[mij];
      |            ~~~~~~~~~~^
      |                      |
      |                      std::vector<int>