Submission #909967

# Submission time Handle Problem Language Result Execution time Memory
909967 2024-01-17T16:53:08 Z nasir_bashirov Easter Eggs (info1cup17_eastereggs) C++11
0 / 100
10 ms 528 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
 
#define db long double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio\
    ios_base::sync_with_stdio(0);\
    cin.tie(0);\
    cout.tie(0)\
 
vi g[550];
bool used[550];
int dp[550], p[550], centroid, n, m;

void calc_p(int node, int par){
    p[node] = par;
    for(int i : g[node]){
        if(i == par)    continue;
        calc_p(i, node);
    }
}

void dfs(int node){
    dp[node] = !used[node];
    for(int i : g[node]){
        dfs(i);
        dp[node] += dp[i];
    }
}

int find_centr(int node){
    for(int i : g[node]){
        if(dp[i] >= n / 2)  return find_centr(i);
    }
    return node;
}

void del_centr(int node){
    used[node] = true;
    for(int i : g[node]){
        del_centr(i);
    }
}

void del_noncentr(int node){
    used[node] = true;
    for(int i : g[node]){
        if(i == centroid)    continue;
        del_noncentr(i);
    }
}

vi get(int node){
    vi v;
    v.push_back(node);
    for(int i : g[node]){
        if(used[i]) continue;
        vi tmp = get(i);
        if(tmp.size() > v.size())   swap(tmp, v);
        for(int i : tmp)    v.push_back(i);
    }
    return v;
}

int findEgg(int N, vii bridges){
    n = N;
    for(int i = 1; i <= n; i++){
        g[i].clear(), used[i] = false, dp[i] = 0, centroid = 0;
    }
    for(pii i : bridges){
        g[i.first].push_back(i.second);
        g[i.second].push_back(i.first);
    }
    calc_p(1, 1);
    for(int i = 1; i <= n; i++){
        g[i].clear(), used[i] = false, dp[i] = 0, centroid = 0;
    }
    for(int i = 2; i <= n; i++){
        g[p[i]].push_back(i);
    }
    while(true){
        if(n == 1){
            for(int i = 1; i <= N; i++){
                if(!used[i])    return i;
            }
        }
        dfs(1);
        centroid = find_centr(1);
        if(query(get(centroid))){
            n = dp[centroid];
            del_noncentr(1);
        }
        else{
            n -= dp[centroid];
            del_centr(centroid);
        }
    }
    return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Runtime error 1 ms 456 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Number of queries: 8
2 Runtime error 3 ms 484 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 528 KB Number of queries: 9
2 Runtime error 2 ms 488 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -