답안 #1015407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015407 2024-07-06T10:18:23 Z Thunnus Burza (COCI16_burza) C++17
160 / 160
46 ms 1480 KB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k, a, b;
    cin >> n >> k;
    vvi adj(n);
    for(int i = 0; i < n - 1; i++){
        cin >> a >> b;
        adj[--a].emplace_back(--b);
        adj[b].emplace_back(a);
    }
    if(pow(k, 2) >= n){
        cout << "DA"; return 0;
    }

    map<int, int> lost;
    vvi cutoff_cover(n), depth_nodes(k + 1);

    function<void(int, int, int)> dfs;
    dfs = [&](int at, int prev, int depth){
        depth_nodes[depth].emplace_back(at);
        if(depth == k){
            lost[at] = sz(lost);
            cutoff_cover[at] = {at};
            return;
        }
        for(int u : adj[at]){
            if(u != prev){
                dfs(u, at, depth + 1);
                cutoff_cover[at].insert(cutoff_cover[at].end(), cutoff_cover[u].begin(), cutoff_cover[u].end());
            }
        }
    };
    dfs(0, 0, 0);

    vector<pii> intervals;
    for(const vi &cc : cutoff_cover){
        if(cc.empty())
            intervals.emplace_back(-1, -1);
        else
            intervals.emplace_back(lost[cc.front()] + 1, lost[cc.back()] + 1);
    }

    vi max_cover(1 << k);
    max_cover[0] = 0;
    for(int ss = 1; ss < (1 << k); ss++){
        int &curr = max_cover[ss];
        for(int to_add = 0; to_add < k; to_add++){
            if(ss & (1 << to_add)){
                int prev = max_cover[ss ^ (1 << to_add)];
                for(int u : depth_nodes[to_add + 1])
                    if(intervals[u].fi <= prev + 1)
                        curr = max(curr, intervals[u].se);

            }
        }
        if(max_cover[ss] == sz(lost)){
            cout << "DA"; return 0;
        }
    }
    cout << "NE";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 600 KB Output is correct
2 Correct 27 ms 1372 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1372 KB Output is correct
2 Correct 28 ms 1372 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 27 ms 1372 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1372 KB Output is correct
2 Correct 25 ms 1372 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 704 KB Output is correct
2 Correct 46 ms 1372 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1372 KB Output is correct
2 Correct 25 ms 1372 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1372 KB Output is correct
2 Correct 39 ms 1372 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1372 KB Output is correct
2 Correct 27 ms 1372 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 24 ms 1480 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 604 KB Output is correct
2 Correct 23 ms 1372 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 600 KB Output is correct
2 Correct 26 ms 1372 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 860 KB Output is correct
2 Correct 26 ms 1372 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 14 ms 860 KB Output is correct
6 Correct 1 ms 348 KB Output is correct