답안 #1082586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1082586 2024-08-31T16:30:50 Z KALARRY Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
12 ms 744 KB
//chockolateman

#include<bits/stdc++.h>
#include "grader.h"


using namespace std;

int n,total = 512,counter;
bool asked[520];
vector<int> adj[520];
vector<int> to_ask;
bool possible[520];

void init(int N)
{
    n = N;
    for(int i = 1 ; i <= n ; i++)
        adj[i].clear();
    total = 0;
    for(int i = 1 ; i <= n ; i++)
    {
        asked[i] = false;
        possible[i] = true;
        total++;
    }
}

void dfs(int v,int p)
{
    counter += possible[v];
    to_ask.push_back(v);
    asked[v] = true;
    for(auto u : adj[v])
    {
        if(counter==total/2)
            return;
        if(u!=p)
            dfs(u,v);
    }
}

int findEgg(int N, vector < pair < int, int > > bridges)
{
    init(N);
    for(auto e : bridges)
    {
        int a = e.first;
        int b = e.second;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    while(total > 1)
    {
        dfs(1,1);
        int res = query(to_ask);
        if(res==1)
        {
            for(int i = 1 ; i <= N ; i++)
                possible[i] &= asked[i];
        }
        else
            for(auto v : to_ask)
                possible[v] = false;
        
        to_ask.clear();
        counter = 0;
        total = 0;
        for(int i = 1 ; i <= N ; i++)
        {
            total += possible[i];
            asked[i] = false;
        }
    }
    for(int i = 1 ; i <= N ; i++)
        if(possible[i])
            return i;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:78:1: warning: control reaches end of non-void function [-Wreturn-type]
   78 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 0 ms 344 KB Number of queries: 4
4 Correct 0 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 600 KB Number of queries: 8
2 Correct 7 ms 740 KB Number of queries: 9
3 Correct 12 ms 740 KB Number of queries: 9
4 Correct 11 ms 344 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 504 KB Number of queries: 9
2 Correct 11 ms 744 KB Number of queries: 9
3 Correct 11 ms 496 KB Number of queries: 9
4 Correct 9 ms 344 KB Number of queries: 9