Submission #687437

# Submission time Handle Problem Language Result Execution time Memory
687437 2023-01-26T12:00:52 Z heeheeheehaaw Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
1 ms 1488 KB
#include <iostream>
#include <vector>
#include "grader.h"

using namespace std;

int hei[50012 + 5], heimax = 0, nrnod;
int parent[50012 + 5];
int fr[50012 + 5], nodlvl[50012 + 5], cnt = 0;
vector<int> muc[50012 + 5];
vector<int> qv;

void reseteaza()
{
    heimax = 0;
    for(int i = 1; i <= 512; i++)
    {
        muc[i].clear();
        hei[i] = 0;
        fr[i] = 0;
    }
    qv.clear();

}

void dfsinit(int nod, int anc)
{
    hei[nod] = hei[anc] + 1;
    heimax = max(heimax, hei[nod]);
    parent[nod] = anc;
    for(auto it: muc[nod])
        if(it != anc)
            dfsinit(it, nod);
}

void dfs(int nod, int anc, int limita, int type)
{
    if(type == 2 && hei[nod] == limita)
        cnt++, nodlvl[cnt] = nod;
    qv.push_back(nod);
    for(auto it: muc[nod])
        if(it != anc && hei[it] <= limita)
            dfs(it, nod, limita, type);
}

void findinterval(int st, int dr, int n)
{
    for(int i = 1; i <= n; i++)
        fr[i] = 0;
    for(int i = st; i <= dr; i++)
    {
        int nod = nodlvl[i];
        while(nod != 1)
        {
            fr[nod]++;
            nod = parent[nod];
        }
    }
    qv.push_back(1);
    for(int i = 2; i <= n; i++)
        if(fr[i] > 0)
            qv.push_back(i);
}

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);
    }
    dfsinit(1, 1);
    int st = 1, dr = heimax;
    /*while(st < dr)
    {
        qv.clear();
        int mij = (st + dr) / 2;
        dfs(1, 1, mij, 1);
        int val = query(qv);
        if(val == true)
            dr = mij;
        else
            st = mij + 1;
    }
    int level = st;
    dfs(1, 1, level, 2);
    st = 1, dr = cnt;
    while(st < dr)
    {
        qv.clear();
        int mij = (st + dr) / 2;
        nrnod = 0;
        findinterval(st, mij, N);
        int val = query(qv);
        if(val == true)
            dr = mij;
        else
            st = mij + 1;
    }*/
    return 1;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:74:9: warning: unused variable 'st' [-Wunused-variable]
   74 |     int st = 1, dr = heimax;
      |         ^~
eastereggs.cpp:74:17: warning: unused variable 'dr' [-Wunused-variable]
   74 |     int st = 1, dr = heimax;
      |                 ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1488 KB The found island is incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1488 KB The found island is incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1488 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -