Submission #916362

# Submission time Handle Problem Language Result Execution time Memory
916362 2024-01-25T18:20:42 Z andrei_iorgulescu Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
17 ms 1004 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

int n;
bool pot[1000];
vector<int>g[1000];
int nrk,cate;
vector<int>noduri;
bool viz[1000];
bool innoduri[1000];

void dfs(int nod)
{
    viz[nod] = true;
    if (nrk == cate / 2)
        return;
    noduri.push_back(nod);
    if (pot[nod] == true)
        nrk++;
    for (auto vecin : g[nod])
        if (!viz[vecin])
            dfs(vecin);
}

int findEgg (int N, vector<pair<int,int>>bridges)
{
    n = N;
    for (int i = 1; i <= n; i++)
        g[i].clear();
    for (int i = 1; i <= n; i++)
        pot[i] = true;
    for (auto it : bridges)
    {
        g[it.first].push_back(it.second);
        g[it.second].push_back(it.first);
    }
    cate = n;
    while (cate > 1)
    {
        for (int i = 1; i <= n; i++)
            viz[i] = false;
        nrk = 0;
        noduri.clear();
        dfs(1);
        int x = query(noduri);
        for (int i = 1; i <= n; i++)
            innoduri[i] = false;
        for (auto it : noduri)
            innoduri[it] = true;
        if (x == 1)
        {
            for (int i = 1; i <= n; i++)
                if (innoduri[i] == false)
                    pot[i] = false;
        }
        else
        {
            for (int i = 1; i <= n; i++)
                if (innoduri[i] == true)
                    pot[i] = false;
        }
        cate = 0;
        for (int i = 1; i <= n; i++)
            if (pot[i] == true)
                cate++;
    }
    for (int i = 1; i <= n; i++)
        if (pot[i] == true)
            return i;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:72:1: warning: control reaches end of non-void function [-Wreturn-type]
   72 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 1 ms 344 KB Number of queries: 4
4 Correct 1 ms 344 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 5 ms 484 KB Number of queries: 8
2 Correct 9 ms 756 KB Number of queries: 9
3 Correct 13 ms 744 KB Number of queries: 9
4 Correct 13 ms 760 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 17 ms 872 KB Number of queries: 9
2 Correct 10 ms 1004 KB Number of queries: 9
3 Correct 12 ms 756 KB Number of queries: 9
4 Correct 12 ms 604 KB Number of queries: 9