답안 #98532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98532 2019-02-23T20:53:07 Z dalgerok Burza (COCI16_burza) C++17
160 / 160
70 ms 984 KB
#include<bits/stdc++.h>
using namespace std;


const int M = 405, N = 20;




int n, k, d[M];
int tin[M], tout[M], timer;
vector < int > g[M], q[M];
bitset < (1 << N) > dp[M];

void dfs(int v, int pr = -1){
    if(d[v] == k){
        tin[v] = timer++;
        tout[v] = timer;
        return;
    }
    tin[v] = timer;
    for(int to : g[v]){
        if(to != pr){
            d[to] = d[v] + 1;
            dfs(to, v);
        }
    }
    tout[v] = timer;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    if(k * k >= n){
        return cout << "DA", 0;
    }
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        x -= 1;
        y -= 1;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0);
    for(int i = 0; i < n; i++){
        if(d[i] == 0){
            continue;
        }
        d[i] -= 1;
        q[tin[i]].push_back(i);
    }
    dp[0][0] = true;
    for(int i = 0; i < timer; i++){
        for(int j = 0; j < (1 << k); j++){
            if(dp[i][j] == true){
                for(auto it : q[i]){
                    if(!((j >> d[it]) & 1)){
                        dp[tout[it]][j | (1 << d[it])] = true;
                    }
                }
            }
        }
    }
    for(int i = 0; i < (1 << k); i++){
        if(dp[timer][i] == true){
            return cout << "DA", 0;
        }
    }
    cout << "NE";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 50 ms 888 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 888 KB Output is correct
2 Correct 38 ms 756 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 57 ms 892 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 888 KB Output is correct
2 Correct 50 ms 732 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 636 KB Output is correct
2 Correct 52 ms 948 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 768 KB Output is correct
2 Correct 47 ms 908 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 912 KB Output is correct
2 Correct 50 ms 860 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 888 KB Output is correct
2 Correct 48 ms 868 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 70 ms 984 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 640 KB Output is correct
2 Correct 43 ms 896 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 66 ms 884 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 640 KB Output is correct
2 Correct 52 ms 916 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 22 ms 640 KB Output is correct
6 Correct 3 ms 512 KB Output is correct