Submission #514744

# Submission time Handle Problem Language Result Execution time Memory
514744 2022-01-18T12:28:56 Z amukkalir Easter Eggs (info1cup17_eastereggs) C++17
87 / 100
17 ms 348 KB
//in repentance and rest is your strenght, in quietness and trust is your salvation
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;
#define pb push_back 

const int nax = 512; 
vector<int> adj[nax+5]; 
int f[nax+5]; 
bool vis[nax+5]; 
int cr = 1; 

void bfs() {
    queue<int> q; 
    q.push(1); 

    while(!q.empty()) {
        int u = q.front(); q.pop(); 
        vis[u] = true; 
        f[cr++] = u; 
        for(int v : adj[u]) {
            if(!vis[v])  q.push(v); 
        }
    }
}

int findEgg (int N, vector < pair < int, int > > bridges)
{   
    for(int i=1; i<=N; i++) {
        adj[i].clear(); 
        f[i] = 0; 
        vis[i] = false; 
    }
    cr = 1; 

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

    bfs(); 

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

        vector<int> vec; 
        for(int i=1; i<=mid; i++) vec.pb(f[i]); 
        if(query(vec)) {
            ans = mid; 
            hi = mid-1; 
        } else {
            lo = mid+1; 
        }
    }

    return f[ans]; 
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=0; i<bridges.size(); i++) {
      |                  ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 200 KB Number of queries: 5
2 Partially correct 1 ms 200 KB Number of queries: 5
3 Partially correct 1 ms 200 KB Number of queries: 5
4 Partially correct 1 ms 200 KB Number of queries: 5
# Verdict Execution time Memory Grader output
1 Correct 5 ms 328 KB Number of queries: 9
2 Correct 10 ms 292 KB Number of queries: 9
3 Correct 14 ms 320 KB Number of queries: 9
4 Correct 13 ms 340 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Partially correct 16 ms 328 KB Number of queries: 10
2 Correct 15 ms 348 KB Number of queries: 9
3 Partially correct 13 ms 348 KB Number of queries: 10
4 Partially correct 17 ms 328 KB Number of queries: 10