답안 #828606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
828606 2023-08-17T12:41:04 Z ma_moutahid Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
1 ms 464 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);
    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)
{
    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]=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:33:1: warning: no return statement in function returning non-void [-Wreturn-type]
   33 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -