답안 #742298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742298 2023-05-16T04:50:34 Z Abrar_Al_Samit Easter Eggs (info1cup17_eastereggs) C++17
10 / 100
382 ms 464 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

const int nax = 513;

bool del[nax];
int sub[nax], par[nax];
vector<int>g[nax];

void dfs(int v, int p = 0) {
    par[v] = p;
    sub[v] = 1;
    for(int u : g[v]) if(u!=p) {
        if(del[u]) continue;

        dfs(u, v);
        sub[v] += sub[u];
    }
}
vector<int>stk;
void dfs2(int v, int p) {
    stk.push_back(v);
    for(int u : g[v]) if(u!=p) {
        if(del[u]) continue;
        dfs2(u, v);
    }
}
int findEgg (int N, vector<pair<int,int>>bridges) {
    memset(del, 0, sizeof del);

    for(int i=1; i<=N; ++i) {
        g[i].clear();
    }
    for(int i=0; i<N-1; ++i) {
        auto [u, v] = bridges[i];
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int cur_size = N;
    while(cur_size>1) {
        int best = 0, r, v;
        for(int i=1; i<=N; ++i) if(!del[i]) {
            dfs(i);

            for(int j=1; j<=N; ++j) if(!del[j]) {
                if(sub[j]<=cur_size/2 && best < sub[j]) {
                    best = sub[j];
                    r = i;
                    v = j;
                } 
            }
        }

        dfs(r);
        dfs2(v, par[v]);

        if(query(stk)) {
            for(int i=1; i<=N; ++i) {
                del[i] = 1;
            }
            cur_size = 0;
            for(int j : stk) {
                del[j] = 0;
                ++cur_size;
            }
        } else {
            for(int j : stk) {
                del[j] = 1;
                --cur_size;
            }
        }
        stk.clear();
    }

    for(int i=1; i<=N; ++i) if(!del[i]) {
        return i;
    }
    assert(0);
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:58:13: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |         dfs2(v, par[v]);
      |         ~~~~^~~~~~~~~~~
eastereggs.cpp:57:12: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |         dfs(r);
      |         ~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Number of queries: 4
2 Partially correct 1 ms 208 KB Number of queries: 5
3 Partially correct 1 ms 208 KB Number of queries: 9
4 Partially correct 2 ms 208 KB Number of queries: 15
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 336 KB Number of queries: 8
2 Partially correct 104 ms 332 KB Number of queries: 12
3 Partially correct 312 ms 336 KB Number of queries: 28
4 Runtime error 29 ms 452 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 316 ms 464 KB Number of queries: 9
2 Partially correct 196 ms 336 KB Number of queries: 12
3 Partially correct 382 ms 336 KB Number of queries: 28
4 Runtime error 7 ms 464 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -