답안 #243035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243035 2020-06-30T08:03:32 Z Joky Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
35 ms 432 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
 
#define mk 513
 
vector <int> g[mk] ,cur_node, cur_set;
 
int mx_size;
void dfs(int u ,int p=-1){
    if(!mx_size)
        return;
    cur_set.push_back(u);
    if(find(cur_node.begin() ,cur_node.end() ,u) != cur_node.end())
        mx_size--;
    for(int v : g[u]) if(v != p) dfs(v , u);
}
vector <int> findSet(int sz){
    mx_size = sz;
    cur_set.clear();
    dfs(1);
    return cur_set;
}
 
int findEgg (int N, vector < pair < int, int > > bridges){
    cur_node.clear();
    for(int i=0; i<=N; i++)
        g[i].clear();
    for(auto&e : bridges)
        g[e.first].push_back(e.second),
        g[e.second].push_back(e.first);
 
    cur_node.resize(N);
    iota(cur_node.begin() ,cur_node.end() ,1);
 
    while(cur_node.size() > 1){
        vector <int> vs = findSet(((int)cur_node.size())/2);
        if(query(vs)){
            vector <int> nv;
            for(int&v : vs)
                if(find(cur_node.begin(), cur_node.end() ,v) !=cur_node.end())
                    nv.push_back(v);
            cur_node = nv;
        }else{
            for(int&v : vs)
                if(find(cur_node.begin() ,cur_node.end() ,v) != cur_node.end())
                    cur_node.erase(find(cur_node.begin() ,cur_node.end() ,v));
        }
    }
 
    return cur_node.front();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Number of queries: 4
2 Correct 5 ms 384 KB Number of queries: 4
3 Correct 5 ms 256 KB Number of queries: 4
4 Correct 5 ms 256 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 384 KB Number of queries: 8
2 Correct 23 ms 384 KB Number of queries: 9
3 Correct 32 ms 384 KB Number of queries: 9
4 Correct 31 ms 424 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 384 KB Number of queries: 9
2 Correct 29 ms 432 KB Number of queries: 9
3 Correct 31 ms 384 KB Number of queries: 9
4 Correct 28 ms 384 KB Number of queries: 9