답안 #412775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412775 2021-05-27T13:32:21 Z aris12345678 Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
21 ms 448 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;

const int mxN = 515;
vector<int> adj[mxN];
vector<int> euler;

void dfs(int u, int p) {
    euler.push_back(u);
    for(auto &v : adj[u]) {
        if(v == p) continue;
        dfs(v, u);
    }
}

int findEgg(int n, vector<pair<int, int> > bridges) {
    euler.clear();
    for(int i = 1; i <= n; i++)
        adj[i].clear();
    for(int i = 0; i < n-1; i++) {
        adj[bridges[i].first].push_back(bridges[i].second);
        adj[bridges[i].second].push_back(bridges[i].first);
    }
    dfs(1, 0);
    int st = 0, en = euler.size()-2, md, ans = -1;
    while(st <= en) {
        md = (st+en)/2;
        vector<int> check;
        for(int i = 0; i <= md; i++)
            check.push_back(euler[i]);
        if(query(check)) {
            en = md-1;
            ans = md;
        } else {
            st = md+1;
        }
    }
    if(ans == -1)
        return euler.back();
    return euler[ans];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 200 KB Number of queries: 4
2 Correct 2 ms 200 KB Number of queries: 4
3 Correct 2 ms 200 KB Number of queries: 4
4 Correct 2 ms 200 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 328 KB Number of queries: 8
2 Correct 15 ms 328 KB Number of queries: 9
3 Correct 21 ms 328 KB Number of queries: 9
4 Correct 17 ms 328 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 448 KB Number of queries: 9
2 Correct 18 ms 328 KB Number of queries: 9
3 Correct 16 ms 328 KB Number of queries: 9
4 Correct 20 ms 340 KB Number of queries: 9