Submission #562659

# Submission time Handle Problem Language Result Execution time Memory
562659 2022-05-14T21:32:05 Z four_specks Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
18 ms 464 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);
    for (auto [u, v] : bridges)
        adj[u - 1].push_back(v - 1),
        adj[v - 1].push_back(u - 1);

    vector<int> order;

    queue<int> q;
    vector<bool> visited(N, 0);
    for (q.push(0), visited[0] = 1; !q.empty();)
    {
        int u = q.front();
        q.pop();

        order.push_back(u);
        for (int v : adj[u])
        {
            if (!visited[v])
                q.push(v), visited[v] = 1;
        }
    }

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

    int lo = 1, hi = N;
    while (lo < hi)
    {
        int mid = (lo + hi) / 2;

        vector<int> islands;
        for (int i = 0; i < mid; i++)
            islands.push_back(order[i] + 1);

        if (query(islands))
            hi = mid;
        else
            lo = mid + 1;
    }

    return order[lo - 1] + 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Number of queries: 4
2 Correct 1 ms 208 KB Number of queries: 4
3 Correct 1 ms 208 KB Number of queries: 4
4 Correct 1 ms 208 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 5 ms 336 KB Number of queries: 8
2 Correct 11 ms 336 KB Number of queries: 9
3 Correct 18 ms 348 KB Number of queries: 9
4 Correct 17 ms 464 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 18 ms 352 KB Number of queries: 9
2 Correct 16 ms 356 KB Number of queries: 9
3 Correct 15 ms 356 KB Number of queries: 9
4 Correct 16 ms 336 KB Number of queries: 9