Submission #199171

# Submission time Handle Problem Language Result Execution time Memory
199171 2020-01-29T19:19:02 Z Bagritsevich_Stepan Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
30 ms 424 KB
#include <bits/stdc++.h>
#include "grader.h"
 
using namespace std;

#define mp make_pair
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair < int, int >
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef long long ll;
typedef long double ld;

const int INF = 2e9;
const ll BIG_INF = 1e18;
const ll MOD = 1e9 + 7;

const int maxn = 550;
vector < int > g[maxn], islands;
int verts[maxn], timer;
bool used[maxn];

void dfs(int v) {
    used[v] = true;
    verts[timer++] = v;
    
    for (int j = 0; j < sz(g[v]); j++) {
        int to = g[v][j];
        if (!used[to])
            dfs(to);
    }
}

bool prov(int max_ind) {
    islands.clear();
    for (int i = 0; i <= max_ind; i++)
        islands.pb(verts[i] + 1);
    
    return query(islands);
}

int bin_search() {
    int l = -1, r = timer - 1;
    while (r - l > 1) {
        int m = (l + r) / 2;
        if (prov(m))
            r = m;
        else
            l = m;
    }
    
    return verts[r] + 1;
}

int findEgg(int N, vector < pair < int, int > > bridges) {
    for (int i = 0; i < N; i++) {
        g[i].clear();
        used[i] = false;
    }
    
    for (int i = 0; i < sz(bridges); i++) {
        int u = bridges[i].fs, v = bridges[i].sc;
        u--;
        v--;
        
        g[u].pb(v);
        g[v].pb(u);
    }
    
    timer = 0;
    dfs(0);
    
    return bin_search();
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Number of queries: 4
2 Correct 5 ms 248 KB Number of queries: 4
3 Correct 6 ms 376 KB Number of queries: 4
4 Correct 6 ms 252 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 10 ms 376 KB Number of queries: 8
2 Correct 15 ms 248 KB Number of queries: 9
3 Correct 27 ms 248 KB Number of queries: 9
4 Correct 19 ms 424 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 30 ms 300 KB Number of queries: 9
2 Correct 27 ms 248 KB Number of queries: 9
3 Correct 26 ms 408 KB Number of queries: 9
4 Correct 20 ms 248 KB Number of queries: 9