답안 #909897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909897 2024-01-17T15:00:15 Z nasir_bashirov Easter Eggs (info1cup17_eastereggs) C++11
10 / 100
27 ms 596 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 sub[550];
vi g[550];
bool used[550];
int dp[550], w[550], centroid, n, m;

void dfs(int node, int par){
    dp[node] = !used[node];
    for(int i : g[node]){
        if(i == par or used[i])    continue;
        dfs(i, node);
        dp[node] += dp[i];
    }
    bool f = true;
    int s = 0;
    for(int i : g[node]){
        s += dp[i];
        if(i == par or used[i])    continue;
        if(dp[i] > m / 2) f = false;
    }
    if(f and m - s <= m / 2 and !used[node])    centroid = node;
}

void del(int node, int spec){
    used[node] = true, w[node] = 0;
    for(int i : g[node]){
        if(i == spec or used[i])    continue;
        del(i, node);
    }
}

vi get(int node, int par){
    vi v;
    v.push_back(node);
    for(int i : g[node]){
        if(i == par or used[i])    continue;
        vi tmp = get(i, node);
        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(), sub[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);
    }
    int cur = centroid, par = cur;
    while(true){
        int par = -1;
        m = 0;
        for(int i = 1; i <= n; i++){
            if(!used[i])    par = i, m++;
        }
        dfs(par, par);
        cur = centroid;
        // cout << par << " " << m << " " << cur << endl;
        int nxt = -1;
        for(int i : g[cur]){
            if(used[i])    continue;
            vi v = get(i, cur);
            if(query(v)){
                nxt = i;
                break;
            }
        }
        if(nxt == -1)   return cur;
        del(cur, nxt);
    }
    return -1;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:71:25: warning: unused variable 'par' [-Wunused-variable]
   71 |     int cur = centroid, par = cur;
      |                         ^~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 344 KB Number of queries: 7
2 Partially correct 1 ms 344 KB Number of queries: 8
3 Partially correct 1 ms 344 KB Number of queries: 9
4 Partially correct 1 ms 596 KB Number of queries: 15
# 결과 실행 시간 메모리 Grader output
1 Partially correct 4 ms 504 KB Number of queries: 14
2 Partially correct 27 ms 496 KB Number of queries: 42
3 Partially correct 24 ms 500 KB Number of queries: 42
4 Runtime error 1 ms 496 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 10 ms 540 KB Number of queries: 17
2 Runtime error 4 ms 504 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -