답안 #716755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
716755 2023-03-31T03:02:56 Z nonono Burza (COCI16_burza) C++14
160 / 160
200 ms 206668 KB
#include "bits/stdc++.h"
#define SZ(x) (int)(x.size())
using namespace std;

const int mxN = 400 + 2;

int n, k, h[mxN], mark[mxN];
int l[mxN], r[mxN], cnt;
int link[mxN][20], dp[1 << 18][mxN];

vector<vector<int>> adj(mxN);

int dfs(int u, int par){
    if(h[u] > k) mark[u] = 1;
    
    int maxH = h[u];
    for(int v : adj[u]){
        if(v == par) continue ;
        
        h[v] = h[u] + 1;
        maxH = max(maxH, dfs(v, u));
    }
    
    if(maxH < k) mark[u] = 1;
    return maxH;
}

void dfs2(int u, int par){
    
    for(int v : adj[u]){
        if(v == par) continue ;
        h[v] = h[u] + 1;
        dfs2(v, u);
        
        if(l[u] == 0) l[u] = l[v];
        r[u] = r[v];
    }
    
    if(h[u] == k){
        cnt ++ ;
        l[u] = cnt;
        r[u] = cnt;
    }
    
    int depth = k - h[u];
    for(int i = l[u]; i <= r[u]; i ++)
        link[i][depth] = r[u];
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> k;
    
    vector<pair<int, int>> edges;
    
    for(int i = 1; i <= n - 1; i ++){
        int u, v;
        cin >> u >> v;
        
        adj[u].push_back(v);
        adj[v].push_back(u);
        
        edges.push_back({u, v});
    }
    
    dfs(1, 0);
    vector<int> a;
    
    for(int i = 1; i <= n; i ++){
        if(mark[i] == 0) a.push_back(i);
        
        h[i] = 0;
        adj[i].clear();
    }
    
    for(auto [u, v] : edges){
        if(mark[u] == 0 && mark[v] == 0){
            int x = upper_bound(a.begin(), a.end(), u) - a.begin();
            int y = upper_bound(a.begin(), a.end(), v) - a.begin();
            
            adj[x].push_back(y);
            adj[y].push_back(x);
        }
    }
    
    n = a.size();
    
    if(k * k >= n){
        cout << "DA\n";
        exit(0);
    }
    
    dfs2(1, 0);
    
    dp[0][1] = 1;
    for(int i = 1; i <= cnt; i ++){
        for(int mask = 0; mask < (1 << k); mask ++){
            if(dp[mask][i] == 0) continue ;
            
            for(int x = ((1 << k) - 1) ^ mask; x > 0; x ^= x & (- x)){
                int j = __builtin_ctz(x & (- x));
                dp[mask | (1 << j)][link[i][j] + 1] = 1;
            }
        }
    }
    
    if(dp[(1 << k) - 1][cnt + 1] == 1) cout << "DA\n"; else cout << "NE\n";
    return 0;
}

Compilation message

burza.cpp: In function 'int main()':
burza.cpp:77:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   77 |     for(auto [u, v] : edges){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 26060 KB Output is correct
2 Correct 167 ms 206552 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 206540 KB Output is correct
2 Correct 169 ms 206476 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 171 ms 206560 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 206668 KB Output is correct
2 Correct 183 ms 206604 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 51868 KB Output is correct
2 Correct 184 ms 206524 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 206544 KB Output is correct
2 Correct 162 ms 206524 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 206476 KB Output is correct
2 Correct 172 ms 206636 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 206616 KB Output is correct
2 Correct 185 ms 206540 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 200 ms 206476 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 51936 KB Output is correct
2 Correct 165 ms 206596 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 26068 KB Output is correct
2 Correct 186 ms 206508 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 103452 KB Output is correct
2 Correct 173 ms 206472 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 79 ms 103448 KB Output is correct
6 Correct 1 ms 340 KB Output is correct