답안 #747055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747055 2023-05-23T14:12:31 Z aramis23 Easter Eggs (info1cup17_eastereggs) C++14
40 / 100
400 ms 840 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

int findEgg (int N, vector < pair < int, int > > bridges)
{
    vector<int> g[N+1];
    for(pair<int,int> p: bridges){
        g[p.first].push_back(p.second);
        g[p.second].push_back(p.first);
    }
    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 = 0;

        while(!res[i])++i;
        q.push(i);

        while(!q.empty()){
            int u = q.front();
            q.pop();

            if(volte[u] || cnt >= k/2)continue;
            volte[u] = true;

            if(res[u])++cnt;
            que.push_back(u);
            for(int v: g[u]){
                if(!volte[v])q.push(v);
            }
        }
        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:38:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for (int i=0; i<que.size(); i++) cerr << que[i] << " ";
      |                       ~^~~~~~~~~~~
eastereggs.cpp:57:1: warning: control reaches end of non-void function [-Wreturn-type]
   57 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 208 KB Number of queries: 4
2 Correct 5 ms 304 KB Number of queries: 4
3 Correct 5 ms 300 KB Number of queries: 4
4 Correct 7 ms 208 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 424 KB Number of queries: 8
2 Execution timed out 462 ms 672 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 619 ms 840 KB Time limit exceeded
2 Halted 0 ms 0 KB -