답안 #243090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243090 2020-06-30T09:45:46 Z VEGAnn Burza (COCI16_burza) C++14
160 / 160
61 ms 1016 KB
#include <bits/stdc++.h>
#define PB push_back
#define i2 array<int,2>
using namespace std;
const int N = 410;
const int PW = (1 << 20);
vector<int> g[N];
vector<i2> qr[N];
bitset<PW> dp[N];
int cnt, h[N], sta[N], ed[N], n, k;

void dfs(int v, int p){
    if (h[v] == k - 1){
        sta[v] = cnt++;
        ed[v] = cnt;

        qr[sta[v]].PB({v, ed[v]});
        return;
    }

    sta[v] = cnt;

    for (int u : g[v]){
        if (u == p) continue;

        h[u] = h[v] + 1;

        dfs(u, v);
    }

    if (v > 0) {
        ed[v] = cnt;

        qr[sta[v]].PB({v, ed[v]});
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> k;

    if (k * k >= n){
        cout << "DA";
        return 0;
    }

    for (int i = 1; i < n; i++){
        int x, y; cin >> x >> y;
        x--; y--;

        g[x].PB(y);
        g[y].PB(x);
    }

    h[0] = -1;

    dfs(0, -1);

    dp[0][0] = 1;

    for (int i = 0; i < cnt; i++)
    for (int msk = 0; msk < (1 << k); msk++){
        if (!dp[i][msk]) continue;

        for (i2 cr : qr[i]) {
            int v = cr[0];
            int j = cr[1];

            if (!(msk & (1 << h[v])))
                dp[j][msk + (1 << h[v])] = 1;
        }
    }

    for (int msk = 0; msk < (1 << k); msk++)
        if (dp[cnt][msk]) {
            cout << "DA";
            return 0;
        }

    cout << "NE";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 512 KB Output is correct
2 Correct 41 ms 760 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 672 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 888 KB Output is correct
2 Correct 40 ms 888 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 61 ms 1016 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 888 KB Output is correct
2 Correct 44 ms 760 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 768 KB Output is correct
2 Correct 54 ms 888 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 760 KB Output is correct
2 Correct 48 ms 888 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 888 KB Output is correct
2 Correct 49 ms 888 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 1004 KB Output is correct
2 Correct 48 ms 888 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 61 ms 888 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 640 KB Output is correct
2 Correct 46 ms 888 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 61 ms 888 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 640 KB Output is correct
2 Correct 53 ms 888 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 24 ms 768 KB Output is correct
6 Correct 5 ms 512 KB Output is correct