Submission #828635

# Submission time Handle Problem Language Result Execution time Memory
828635 2023-08-17T12:57:06 Z ma_moutahid Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
68 ms 131072 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

vector<int>st_size;
vector<vector<int>>graph;
vector<bool>active;
int st(int node, int parent){
    st_size[node]=1;
    for(int &child:graph[node]){
        if(child==parent || !active[child])continue;
        st_size[node]+=st(child,node);
    }
    return st_size[node];
}

int find_centroid(int node, int parent, int size){
    for(int child:graph[node]){
        if(child==parent || !active[child])continue;
        if(st_size[child]>=size/2)return(find_centroid(child,node,size));
    }
    return node;
}
vector<int>t;
vector<int> build_the_tree(int node, int parent){
    t.push_back(node+1);
    for(int child:graph[node]){
        if(child==parent || !active[child])continue;
        build_the_tree(child,node);
    }
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
    graph.clear();
    st_size.clear();
    active.clear();
    st_size.resize(N);
    graph.resize(N);
    active.resize(N,true);
    for(int i=0;i<N-1;i++){
        graph[--bridges[i].first].push_back(--bridges[i].second);
        graph[bridges[i].second].push_back(bridges[i].first);
    }
    int total=N;
    int parent=0;
    while(total>1){
        t.clear();
        int centroid=find_centroid(parent,-1,st(parent,-1));
        active[centroid]=0;
        build_the_tree(parent,-1);
        if(query(t)){
            active.resize(N,0);
            for(int i:t)active[i-1]=true;
            total=st_size[parent]-st_size[centroid];
        }
        else {
            for(int i:t)active[i]=false;
            active[centroid]=true;
            total=st_size[centroid];
            parent=centroid;
        }
    }
    return parent;
}

Compilation message

eastereggs.cpp: In function 'std::vector<int> build_the_tree(int, int)':
eastereggs.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
   32 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 68 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -