Submission #671444

# Submission time Handle Problem Language Result Execution time Memory
671444 2022-12-13T05:11:53 Z dooompy Easter Eggs (info1cup17_eastereggs) C++17
87 / 100
20 ms 2704 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

vector<int> adj[100005];

vector<int> straight;

bool able(int idx) {
    vector<int> temp = straight;
    temp.resize(idx);

    return query(temp);
}


void dfs(int node, int par = -1) {
    straight.push_back(node);

    for (auto nxt : adj[node]) {
        if (nxt == par) continue;
        dfs(nxt, node);
    }
}

int findEgg (int N, vector < pair < int, int > > bridges)
{
    straight.clear();
    for (int i = 0; i <= N; i++) adj[i].clear();

    for (int i = 0; i < bridges.size(); i++) {
        adj[bridges[i].first].push_back(bridges[i].second);
        adj[bridges[i].second].push_back(bridges[i].first);
    }

    dfs(1);

    int n = straight.size();

    int lo = 1, hi = n;

    int ans = -1;
    while (lo <= hi) {
        int mid = (lo + hi) / 2;

        if (able(mid)) {
            hi = mid - 1;
            ans = straight[mid-1];
        } else lo = mid + 1;
    }

    return ans;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < bridges.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2640 KB Number of queries: 5
2 Partially correct 2 ms 2640 KB Number of queries: 5
3 Partially correct 2 ms 2640 KB Number of queries: 5
4 Partially correct 2 ms 2640 KB Number of queries: 5
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2668 KB Number of queries: 9
2 Correct 11 ms 2692 KB Number of queries: 9
3 Correct 16 ms 2684 KB Number of queries: 9
4 Correct 20 ms 2692 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Partially correct 14 ms 2704 KB Number of queries: 10
2 Correct 19 ms 2692 KB Number of queries: 9
3 Partially correct 16 ms 2640 KB Number of queries: 10
4 Partially correct 16 ms 2684 KB Number of queries: 10