답안 #1116592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116592 2024-11-21T21:18:36 Z vladilius Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
18 ms 732 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

int query(vector<int> f);

int findEgg(int n, vector<pii> ed){
    vector<int> g[n + 1];
    for (auto [x, y]: ed){
        g[x].pb(y); g[y].pb(x);
    }
    
    vector<int> a(n);
    int timer = 0;
    function<void(int, int)> dfs = [&](int v, int pr){
        a[timer++] = v;
        for (int i: g[v]){
            if (i == pr) continue;
            dfs(i, v);
        }
    };
    dfs(1, 0);
    
    auto check = [&](int x){
        vector<int> f;
        for (int i = 0; i <= x; i++){
            f.pb(a[i]);
        }
        return query(f);
    };
    
    int l = 0, r = n - 1;
    while (l + 1 < r){
        int m = (l + r) / 2;
        if (check(m)){
            r = m;
        }
        else {
            l = m + 1;
        }
    }
    
    if (check(l)) r = l;
    return a[r];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Number of queries: 4
2 Correct 2 ms 336 KB Number of queries: 4
3 Correct 2 ms 336 KB Number of queries: 4
4 Correct 2 ms 336 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 336 KB Number of queries: 8
2 Correct 12 ms 732 KB Number of queries: 9
3 Correct 16 ms 336 KB Number of queries: 9
4 Correct 15 ms 336 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 336 KB Number of queries: 9
2 Correct 17 ms 496 KB Number of queries: 9
3 Correct 18 ms 504 KB Number of queries: 9
4 Correct 15 ms 484 KB Number of queries: 9