답안 #551967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551967 2022-04-22T04:30:39 Z aadit_ambadkar Burza (COCI16_burza) C++11
0 / 160
87 ms 2764 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> adj[402], q[402];
int n, k, st[402], ed[402], level[402], pz;

void dfs(int u, int p) {
    if (u) {
        level[u]=level[p]+1;
    }
    if (level[u]==k-1) {
        st[u]=pz++;
        ed[u]=pz;
    }
    st[u]=pz;
    for (auto i : adj[u]) {
        if (i!=p) dfs(i, u);
    }
    ed[u]=pz;
}

bool dp[402][(1<<20)];

bool solve() {
    dp[0][0]=1;
    for (int i = 1; i < n; i++) {
        q[st[i]].push_back(i);
    }
    for (int i = 0; i < pz; i++) {
        for (int j = 0; j < (1<<k); j++) {
            if (!dp[i][j]) continue;
            for (auto it : q[i]) {
                if (!(j >> level[it] & 1)) {
                    dp[ed[it]][j | (1<<level[it])]=1;
                }
            }
        }
    }
    for (int j = 0; j < (1<<k); j++) {
        if (dp[pz][j]) return 1;
    }
    return 0;
}

int main() {
    cin >> n >> k;
    if (k*k >= n) {
        cout << "DE\n";
        return 0;
    }
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    level[0]=-1;
    dfs(0, -1);
    cout << (solve() ? "DA\n" : "NE\n");
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 852 KB Output is correct
2 Correct 66 ms 2564 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 2568 KB Output is correct
2 Correct 62 ms 2504 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 2540 KB Output is correct
2 Correct 69 ms 2496 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1068 KB Output is correct
2 Correct 61 ms 2508 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 2320 KB Output is correct
2 Correct 53 ms 2560 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 2252 KB Output is correct
2 Correct 60 ms 2536 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 2728 KB Output is correct
2 Correct 58 ms 2404 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 1032 KB Output is correct
2 Correct 65 ms 2380 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 640 KB Output is correct
2 Correct 80 ms 2468 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1412 KB Output is correct
2 Correct 68 ms 2764 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -