답안 #963104

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963104 2024-04-14T14:12:46 Z biank Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
14 ms 992 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

const int MAX_N = 512;

#define sz(x) int(x.size())

vector<int> adj[MAX_N], islands;

void dfs(int u, int p = -1) {
    islands.push_back(u + 1);
    for (int v : adj[u]) {
        if (v != p) dfs(v, u);
    }
}

int findEgg (int N, vector<pair<int, int>> bridges) {
    islands.clear();
    for (int i = 0; i < N; i++) adj[i].clear();
    for (int i = 0; i < N - 1; i++) {
        auto [u, v] = bridges[i];
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0);
    int l = 0, r = N;
    vector<int> v;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        while (sz(v) > m) v.pop_back();
        while (sz(v) < m) v.push_back(islands[sz(v)]);
        if (query(v)) {
            r = m;
        } else {
            l = m;
        }
    }
    return islands[l];
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |         auto [u, v] = bridges[i];
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 1 ms 344 KB Number of queries: 4
4 Correct 1 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 728 KB Number of queries: 8
2 Correct 7 ms 984 KB Number of queries: 9
3 Correct 11 ms 992 KB Number of queries: 9
4 Correct 13 ms 860 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 760 KB Number of queries: 9
2 Correct 9 ms 736 KB Number of queries: 9
3 Correct 14 ms 724 KB Number of queries: 9
4 Correct 12 ms 752 KB Number of queries: 9