답안 #529693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529693 2022-02-23T13:01:51 Z ohohorz Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
21 ms 512 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

const int MAXN = 520;
set<int> g[MAXN];
int n;
vector<int> ord;

void dfs(int u,int p){
    ord.push_back(u);
    for(auto v:g[u]) if(v != p){
        dfs(v, u);
    }
}



int findEgg (int N, vector < pair < int, int > > bridges){   
    /*
    set<int> g[MAXN];
int n, sub[MAXN];
vector<int> cenTree[MAXN], what[MAXN];
    */
   for(int i = 0;i <MAXN;i++){
       g[i].clear();
   }
   ord.clear();
    
    n = N;
    for(int i = 0;i < N-1;i++){
        int u = bridges[i].first;
        int v = bridges[i].second;
        g[u].insert(v);
        g[v].insert(u);
    }
    dfs(1, 0);
    int l = 0, r = n - 2;
    int mx = 1e9;
    while(l <= r){
        int m = (l + r) >> 1LL;
        vector<int> to;
        for(int i = 0;i <= m;i++) to.push_back(ord[i]);
        int q = query(to);
        if(q == 1){
            mx = min(mx, m);
            r = m -1;
        } else l = m + 1;
    }
    if(mx == 1e9) return ord.back();
    
    return ord[mx];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 200 KB Number of queries: 4
2 Correct 2 ms 312 KB Number of queries: 4
3 Correct 1 ms 316 KB Number of queries: 4
4 Correct 1 ms 200 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 368 KB Number of queries: 8
2 Correct 11 ms 328 KB Number of queries: 9
3 Correct 17 ms 380 KB Number of queries: 9
4 Correct 16 ms 384 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 400 KB Number of queries: 9
2 Correct 17 ms 328 KB Number of queries: 9
3 Correct 15 ms 396 KB Number of queries: 9
4 Correct 20 ms 512 KB Number of queries: 9