Submission #747058

# Submission time Handle Problem Language Result Execution time Memory
747058 2023-05-23T14:20:42 Z aramis23 Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
14 ms 376 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

vector<vector<int> > g(513);
bool f=false;

int findEgg (int N, vector < pair < int, int > > bridges)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (!f) {
        for(pair<int,int> p: bridges){
            g[p.first].push_back(p.second);
            g[p.second].push_back(p.first);
        }
        f=true;
    }
    vector<bool> res(N+1, 1);

    for(int k = N; k > 1;){
        vector<bool> volte(N+1, false);
        queue<int> q;
        vector<int> que;
        int i =1, cnt = 1;

        while(!res[i])++i;
        q.push(i);
        volte[i]=true;
        while(!q.empty()){
            int u = q.front();
            q.pop();
            que.push_back(u);
            for(int v: g[u]){
                if(!volte[v] && cnt < k/2) {
                    q.push(v);
                    volte[v]=true;
                    if (res[v])cnt++;
                }
            }
        }
        int a = query(que);
        //for (int i=0; i<que.size(); i++) cerr << que[i] << " ";
        //cerr << "\n";
        if(!a){
            k-=cnt;
            for(int i = 1 ; i<= N; ++i){
                if(volte[i])res[i] = false;
            }
        }
        else{
            k=cnt;
            for(int i = 1 ; i<= N; ++i){
                if(!volte[i])res[i] = false;
            }
        }
        //for(int i = 1; i <= N; ++i)cerr<<res[i]<<' ';
        //cerr<<'\n';
    }

    for(int i = 1; i <= N; ++i)if(res[i])return i;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:20:28: warning: control reaches end of non-void function [-Wreturn-type]
   20 |     vector<bool> res(N+1, 1);
      |                            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Number of queries: 4
2 Correct 1 ms 208 KB Number of queries: 4
3 Correct 1 ms 208 KB Number of queries: 4
4 Correct 1 ms 336 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 4 ms 336 KB Number of queries: 8
2 Correct 8 ms 336 KB Number of queries: 9
3 Correct 13 ms 372 KB Number of queries: 9
4 Correct 14 ms 376 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 10 ms 336 KB Number of queries: 9
2 Correct 11 ms 376 KB Number of queries: 9
3 Correct 11 ms 336 KB Number of queries: 9
4 Correct 11 ms 336 KB Number of queries: 9