답안 #330460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
330460 2020-11-25T11:25:22 Z Falcon Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
28 ms 492 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

int findEgg (int N, vector<pair<int, int>> bridges) {

    vector<vector<int>> adj(N + 1);
    for(const auto& [u, v] : bridges)
        adj[u].push_back(v), adj[v].push_back(u);

    vector<bool> vis(N + 1);
    vector<int> order{1}; order.reserve(N);
    for(int i = 0; i < int(order.size()); ++i) {
        int u{order[i]}; vis[u] = true;
        for(int v : adj[u])
            if(!vis[v]) order.push_back(v);
    }

    assert(order.size() == N);

    int i{};
    for(int t = 1 << __lg(N); t > 0; t >>= 1)
        if(i + t < N
           && !query(vector<int>(order.begin(), order.begin() + i + t)))
            i += t;
    
    return order[i];
}

Compilation message

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from grader.h:1,
                 from eastereggs.cpp:2:
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:20:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     assert(order.size() == N);
      |            ~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Number of queries: 4
2 Correct 1 ms 364 KB Number of queries: 4
3 Correct 1 ms 364 KB Number of queries: 4
4 Correct 1 ms 364 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Number of queries: 8
2 Correct 15 ms 364 KB Number of queries: 9
3 Correct 21 ms 364 KB Number of queries: 9
4 Correct 21 ms 432 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 236 KB Number of queries: 9
2 Correct 20 ms 364 KB Number of queries: 9
3 Correct 26 ms 364 KB Number of queries: 9
4 Correct 24 ms 492 KB Number of queries: 9